1 | <?php |
||
19 | class Endpoint implements Countable, IteratorAggregate, ArrayAccess, Arrayable, Jsonable |
||
20 | { |
||
21 | use DelegatedArrayTrait; |
||
22 | |||
23 | /** |
||
24 | * @var FieldCollection |
||
25 | */ |
||
26 | protected $fields; |
||
27 | |||
28 | /** |
||
29 | * @var AbstractDataSource |
||
30 | */ |
||
31 | protected $source; |
||
32 | |||
33 | protected $auto = false; |
||
34 | |||
35 | public function __construct($source = []) |
||
40 | |||
41 | public static function auto($source) |
||
47 | |||
48 | protected function initSource($source) |
||
52 | |||
53 | /** |
||
54 | * @param string $name |
||
55 | * @param array $arguments |
||
56 | * |
||
57 | * @return Field|static|mixed |
||
58 | */ |
||
59 | public function __call($name, $arguments) |
||
75 | |||
76 | public function source($newSource = null) |
||
86 | |||
87 | /** |
||
88 | * Collection containing all the fields in the form. |
||
89 | * |
||
90 | * @return FieldCollection |
||
91 | */ |
||
92 | public function fields() |
||
96 | |||
97 | /** |
||
98 | * Get a field by name (dotted offset). |
||
99 | * |
||
100 | * (you can also use array notation like: |
||
101 | * <code>$form['author.name']</code> |
||
102 | * |
||
103 | * @param string $name |
||
104 | * |
||
105 | * @return Field |
||
106 | */ |
||
107 | public function field($name) |
||
111 | |||
112 | /** |
||
113 | * Get the fields value as an associative array. |
||
114 | * By default a nested array is returned. |
||
115 | * Passing true as the first parameter, a flat |
||
116 | * array will be returned, with dotted offsets |
||
117 | * as the keys. |
||
118 | * |
||
119 | * @param bool $flat |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | public function toArray($flat = false) |
||
127 | |||
128 | /** |
||
129 | * Required by DelegatedArrayTrait. |
||
130 | * |
||
131 | * @return FieldCollection |
||
132 | */ |
||
133 | protected function getDelegatedStorage() |
||
137 | |||
138 | /** |
||
139 | * Sets the fields values back to the models. |
||
140 | */ |
||
141 | public function writeSource() |
||
147 | |||
148 | /** |
||
149 | * Fills the form with the values coming from the DB |
||
150 | * and HTTP input. |
||
151 | */ |
||
152 | public function populate() |
||
157 | |||
158 | public function fromSource() |
||
162 | |||
163 | public function fromInput() |
||
167 | |||
168 | public function from($source) |
||
176 | |||
177 | /** |
||
178 | * Saves the models back to the database. |
||
179 | */ |
||
180 | public function save() |
||
184 | |||
185 | /** |
||
186 | * Validates the form, then sets eventual errors on each field. |
||
187 | * |
||
188 | * @return mixed |
||
189 | */ |
||
190 | public function validate() |
||
196 | |||
197 | /** |
||
198 | * @return mixed |
||
199 | */ |
||
200 | public function errors() |
||
206 | |||
207 | /** |
||
208 | * Convert the object to its JSON representation. |
||
209 | * |
||
210 | * @param int $options |
||
211 | * @return string |
||
212 | */ |
||
213 | public function toJson($options = 0) |
||
223 | |||
224 | protected function getKey() |
||
229 | |||
230 | protected function process() |
||
252 | |||
253 | protected function load() |
||
261 | } |
||
262 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: