1 | <?php |
||
30 | class CollectionIterator extends ResultIterator |
||
31 | { |
||
32 | /** |
||
33 | * @var Session |
||
34 | */ |
||
35 | protected $session; |
||
36 | |||
37 | /** |
||
38 | * @var Projection |
||
39 | */ |
||
40 | protected $projection; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $filters = []; |
||
46 | |||
47 | /** |
||
48 | * @var HydrationPlan |
||
49 | */ |
||
50 | protected $hydration_plan; |
||
51 | |||
52 | /** |
||
53 | * @var PgEntity |
||
54 | */ |
||
55 | private $entity_converter; |
||
56 | |||
57 | /** |
||
58 | * __construct |
||
59 | * |
||
60 | * Constructor |
||
61 | * |
||
62 | * @access public |
||
63 | * @param ResultHandler $result |
||
64 | * @param Session $session |
||
65 | * @param Projection $projection |
||
66 | */ |
||
67 | public function __construct(ResultHandler $result, Session $session, Projection $projection) |
||
79 | |||
80 | /** |
||
81 | * get |
||
82 | * |
||
83 | * @see ResultIterator |
||
84 | * @return FlexibleEntityInterface |
||
85 | */ |
||
86 | public function get($index) |
||
90 | |||
91 | /** |
||
92 | * parseRow |
||
93 | * |
||
94 | * Convert values from Pg. |
||
95 | * |
||
96 | * @access protected |
||
97 | * @param array $values |
||
98 | * @return FlexibleEntityInterface |
||
99 | * @see ResultIterator |
||
100 | */ |
||
101 | public function parseRow(array $values) |
||
108 | |||
109 | /** |
||
110 | * launchFilters |
||
111 | * |
||
112 | * Launch filters on the given values. |
||
113 | * |
||
114 | * @access protected |
||
115 | * @param array $values |
||
116 | * @throws ModelException if return is not an array. |
||
117 | * @return array |
||
118 | */ |
||
119 | protected function launchFilters(array $values) |
||
131 | |||
132 | /** |
||
133 | * registerFilter |
||
134 | * |
||
135 | * Register a new callable filter. All filters MUST return an associative |
||
136 | * array with field name as key. |
||
137 | * |
||
138 | * @access public |
||
139 | * @param callable $callable the filter. |
||
140 | * @return CollectionIterator $this |
||
141 | * @throws ModelException |
||
142 | */ |
||
143 | public function registerFilter($callable) |
||
156 | |||
157 | /** |
||
158 | * clearFilters |
||
159 | * |
||
160 | * Empty the filter stack. |
||
161 | */ |
||
162 | public function clearFilters() |
||
168 | |||
169 | /** |
||
170 | * extract |
||
171 | * |
||
172 | * Return an array of entities extracted as arrays. |
||
173 | * |
||
174 | * @access public |
||
175 | * @return array |
||
176 | */ |
||
177 | public function extract() |
||
187 | |||
188 | /** |
||
189 | * slice |
||
190 | * |
||
191 | * see @ResultIterator |
||
192 | * |
||
193 | * @access public |
||
194 | * @param string $name |
||
195 | * @return array |
||
196 | */ |
||
197 | public function slice($name) |
||
201 | |||
202 | /** |
||
203 | * @param Closure $callback |
||
204 | * @return array |
||
205 | */ |
||
206 | public function map(Closure $callback) |
||
210 | |||
211 | |||
212 | /** |
||
213 | * convertSlice |
||
214 | * |
||
215 | * Convert a slice. |
||
216 | * |
||
217 | * @access protected |
||
218 | * @param array $values |
||
219 | * @param string $name |
||
220 | * @return array |
||
221 | */ |
||
222 | protected function convertSlice(array $values, $name) |
||
234 | } |
||
235 |
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 implementation 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 interface: