Field.php
25 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Factory; |
| 4 | |
| 5 | use ReflectionClass; |
| 6 | use Give\Framework\FieldsAPI\FormField; |
| 7 | use Give\Framework\FieldsAPI\FormField\FieldTypes; |
| 8 | use Give\Framework\FieldsAPI\Factory\Exception\TypeNotSupported; |
| 9 | |
| 10 | class Field { |
| 11 | |
| 12 | public static function __callStatic( $type, $parameters ) { |
| 13 | $reflectionClass = new ReflectionClass( FieldTypes::class ); |
| 14 | $types = array_flip( $reflectionClass->getConstants() ); |
| 15 | if ( ! isset( $types[ $type ] ) ) { |
| 16 | throw new TypeNotSupported( $type ); |
| 17 | } |
| 18 | return self::make( $type, array_shift( $parameters ) ); |
| 19 | } |
| 20 | |
| 21 | protected static function make( $type, $name ) { |
| 22 | return new FormField( $type, $name ); |
| 23 | } |
| 24 | } |
| 25 |