1 | <?php |
||
16 | abstract class AbstractField |
||
17 | { |
||
18 | /** |
||
19 | * @var DataSet The DataSet from which this field take values by path. |
||
20 | */ |
||
21 | protected $dataSet; |
||
22 | |||
23 | /** |
||
24 | * @var mixed Value to compare parse result. |
||
25 | */ |
||
26 | protected $assert; |
||
27 | |||
28 | /** |
||
29 | * @var array Cache to found values. |
||
30 | */ |
||
31 | protected $propertyCache = []; |
||
32 | |||
33 | /** |
||
34 | * Read and process data from Stream. |
||
35 | * |
||
36 | * @api |
||
37 | * @param AbstractStream $stream Stream from which field should read. |
||
38 | * @return mixed Processed value. |
||
39 | */ |
||
40 | abstract public function parse(AbstractStream $stream); |
||
41 | |||
42 | /** |
||
43 | * Associate given values to appropriate class properties. |
||
44 | * |
||
45 | * @param array $properties Associative array of properties values. |
||
46 | */ |
||
47 | 54 | public function configure(array $properties) |
|
56 | |||
57 | /** |
||
58 | * Return DataSet instance from which this field take back linked values. |
||
59 | * |
||
60 | * @return DataSet DataSet corresponding this field. |
||
61 | */ |
||
62 | 6 | public function getDataSet() |
|
66 | |||
67 | /** |
||
68 | * Set to field DataSet instance for back links. |
||
69 | * |
||
70 | * @param DataSet $dataSet DataSet ro correspond to this field. |
||
71 | * @return self For chaining. |
||
72 | */ |
||
73 | 9 | public function setDataSet(DataSet $dataSet) |
|
78 | |||
79 | /** |
||
80 | * @return mixed |
||
81 | */ |
||
82 | 19 | public function getAssert() |
|
86 | |||
87 | /** |
||
88 | * @param mixed $assert |
||
89 | * @return $this |
||
90 | */ |
||
91 | 14 | public function setAssert($assert) |
|
96 | |||
97 | /** |
||
98 | * Check that given value is valid. |
||
99 | * |
||
100 | * @param $value mixed Checked value. |
||
101 | * @return true On success validation. |
||
|
|||
102 | * @throws AssertException On assertion fail. |
||
103 | */ |
||
104 | 19 | public function validate($value) |
|
131 | |||
132 | /** |
||
133 | * Process, set and return given property. |
||
134 | * |
||
135 | * Find given property in DataSet if it was set as path string and return it. |
||
136 | * Otherwise already set value will be returned. |
||
137 | * |
||
138 | * @param string $name Property name. |
||
139 | * @return int|string|array|null Found or already set property value. |
||
140 | */ |
||
141 | 32 | protected function resolveProperty($name) |
|
150 | |||
151 | /** |
||
152 | * Find value in DataSet by given value if it is a path string. |
||
153 | * Otherwise given value will be returned. |
||
154 | * |
||
155 | * @param $value |
||
156 | * @return array|int|null|string |
||
157 | * @since 0.2 |
||
158 | */ |
||
159 | 31 | private function resolveValue($value) |
|
176 | } |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.