1 | <?php |
||
9 | class FieldsFactory |
||
10 | { |
||
11 | /** |
||
12 | * list of all the available field classes. |
||
13 | * |
||
14 | * this list is used when inferring field type from a value |
||
15 | * infer works by trying to case the value to the field, in the fieldClasses order |
||
16 | * first field that doesn't raise exception on infer wins |
||
17 | */ |
||
18 | public static $fieldClasses = [ |
||
19 | '\\frictionlessdata\\tableschema\\Fields\\IntegerField', |
||
20 | '\\frictionlessdata\\tableschema\\Fields\\NumberField', |
||
21 | '\\frictionlessdata\\tableschema\\Fields\\StringField', |
||
22 | |||
23 | // these fields will not be inferred - StringField will catch all values before it reaches these |
||
24 | '\\frictionlessdata\\tableschema\\Fields\\YearMonthField', |
||
25 | '\\frictionlessdata\\tableschema\\Fields\\YearField', |
||
26 | '\\frictionlessdata\\tableschema\\Fields\\TimeField', |
||
27 | '\\frictionlessdata\\tableschema\\Fields\\ObjectField', |
||
28 | '\\frictionlessdata\\tableschema\\Fields\\GeopointField', |
||
29 | '\\frictionlessdata\\tableschema\\Fields\\GeojsonField', |
||
30 | '\\frictionlessdata\\tableschema\\Fields\\DurationField', |
||
31 | '\\frictionlessdata\\tableschema\\Fields\\DatetimeField', |
||
32 | '\\frictionlessdata\\tableschema\\Fields\\DateField', |
||
33 | '\\frictionlessdata\\tableschema\\Fields\\BooleanField', |
||
34 | '\\frictionlessdata\\tableschema\\Fields\\ArrayField', |
||
35 | '\\frictionlessdata\\tableschema\\Fields\\AnyField', |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * get a new field object in the correct type according to the descriptor. |
||
40 | * |
||
41 | * @param object|array $descriptor |
||
42 | * |
||
43 | * @return BaseField |
||
44 | * |
||
45 | * @throws \Exception |
||
46 | */ |
||
47 | public static function field($descriptor, $name = null) |
||
73 | |||
74 | /** |
||
75 | * @param $val |
||
76 | * @param null $descriptor |
||
77 | * |
||
78 | * @return mixed |
||
79 | * |
||
80 | * @throws FieldValidationException |
||
81 | */ |
||
82 | public static function infer($val, $descriptor = null, $lenient = false) |
||
96 | } |
||
97 |