1 | <?php |
||
7 | abstract class BaseField |
||
8 | { |
||
9 | public function __construct($descriptor=null) |
||
13 | |||
14 | public function descriptor() |
||
18 | |||
19 | public function name() |
||
23 | |||
24 | /** |
||
25 | * try to create a field object based on the descriptor |
||
26 | * by default uses the type attribute |
||
27 | * return the created field object or false if the descriptor does not match this field |
||
28 | * @param object $descriptor |
||
29 | * @return bool|BaseField |
||
30 | */ |
||
31 | public static function inferDescriptor($descriptor) |
||
39 | |||
40 | /** |
||
41 | * try to create a new field object based on the given value |
||
42 | * @param mixed $val |
||
43 | * @param null|object $descriptor |
||
44 | * @param bool @lenient |
||
45 | * @return bool|BaseField |
||
46 | */ |
||
47 | public static function infer($val, $descriptor=null, $lenient=false) |
||
58 | |||
59 | public function inferProperties($val, $lenient) |
||
65 | |||
66 | /** |
||
67 | * @param mixed $val |
||
68 | * @return mixed |
||
69 | * @throws \frictionlessdata\tableschema\Exceptions\FieldValidationException; |
||
70 | */ |
||
71 | public function validateValue($val) |
||
79 | |||
80 | /** |
||
81 | * @param mixed $val |
||
82 | * @return mixed |
||
83 | * @throws \frictionlessdata\tableschema\Exceptions\FieldValidationException; |
||
84 | */ |
||
85 | public function castValue($val) |
||
89 | |||
90 | /** |
||
91 | * get a unique identifier for this field |
||
92 | * used in the inferring process |
||
93 | * this is usually the type, but can be modified to support more advanced inferring process |
||
94 | * @param bool @lenient |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getInferIdentifier($lenient=false) |
||
101 | |||
102 | /** |
||
103 | * should be implemented by extending classes to return the table schema type of this field |
||
104 | * @return string |
||
105 | */ |
||
106 | static public function type() |
||
110 | |||
111 | protected $descriptor; |
||
112 | |||
113 | protected function getValidationException($errorMsg, $val=null) |
||
123 | } |