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