1 | <?php |
||
43 | class Resolver extends ConfigDelegator implements ResolverInterface, AutoWiringInterface |
||
44 | { |
||
45 | /** |
||
46 | * The outer master |
||
47 | * |
||
48 | * @var Container |
||
49 | * @access protected |
||
50 | */ |
||
51 | protected $master; |
||
52 | |||
53 | /** |
||
54 | * The object resolver |
||
55 | * |
||
56 | * @var ObjectResolver |
||
57 | * @access protected |
||
58 | */ |
||
59 | protected $object_resolver; |
||
60 | |||
61 | /** |
||
62 | * The parameter resolver |
||
63 | * |
||
64 | * @var ConfigInterface |
||
65 | * @access protected |
||
66 | */ |
||
67 | protected $config_resolver; |
||
68 | |||
69 | /** |
||
70 | * Container related definition starting node at $config |
||
71 | * |
||
72 | * @var string |
||
73 | * @access protected |
||
74 | */ |
||
75 | protected $base_node; |
||
76 | |||
77 | /** |
||
78 | * Autowiring: automatically resolve classname if it is a defined class |
||
79 | * |
||
80 | * @var bool |
||
81 | * @access protected |
||
82 | */ |
||
83 | protected $auto = true; |
||
84 | |||
85 | /** |
||
86 | * @param Container $master the master |
||
87 | * @param ConfigInterface $config used for parameter resolving |
||
88 | * @param string $nodeName |
||
89 | * @access public |
||
90 | */ |
||
91 | public function __construct( |
||
114 | |||
115 | /** |
||
116 | * {@inheritDoc} |
||
117 | */ |
||
118 | public function resolve(&$toResolve) |
||
125 | |||
126 | /** |
||
127 | * {@inheritDoc} |
||
128 | */ |
||
129 | public function setObjectResolver() |
||
139 | |||
140 | /** |
||
141 | * {@inheritDoc} |
||
142 | */ |
||
143 | public function getInSection(/*# string */ $id, /*# string */ $section) |
||
147 | |||
148 | /** |
||
149 | * {@inheritDoc} |
||
150 | */ |
||
151 | public function hasInSection( |
||
157 | |||
158 | /** |
||
159 | * {@inheritDoc} |
||
160 | */ |
||
161 | public function setInSection( |
||
168 | |||
169 | /** |
||
170 | * {@inheritDoc} |
||
171 | */ |
||
172 | public function getService(/*# string */ $id = '') |
||
176 | |||
177 | /** |
||
178 | * {@inheritDoc} |
||
179 | */ |
||
180 | public function hasService(/*# string */ $id = '')/*# : bool */ |
||
188 | |||
189 | /** |
||
190 | * {@inheritDoc} |
||
191 | */ |
||
192 | public function setService( |
||
205 | |||
206 | /** |
||
207 | * {@inheritDoc} |
||
208 | */ |
||
209 | public function getMapping(/*# string */ $id = '') |
||
213 | |||
214 | /** |
||
215 | * {@inheritDoc} |
||
216 | */ |
||
217 | public function hasMapping(/*# string */ $id = '')/*# : bool */ |
||
221 | |||
222 | /** |
||
223 | * {@inheritDoc} |
||
224 | */ |
||
225 | public function setMapping(/*# string */ $from, $to) |
||
229 | |||
230 | /** |
||
231 | * {@inheritDoc} |
||
232 | */ |
||
233 | public function autoWiring(/*# bool */ $on = true) |
||
238 | |||
239 | /** |
||
240 | * Generate new id base on base and section |
||
241 | * |
||
242 | * @param string $id |
||
243 | * @param string $section |
||
244 | * @return string |
||
245 | * @access protected |
||
246 | */ |
||
247 | protected function getSectionId( |
||
254 | |||
255 | /** |
||
256 | * If autowiring is on, and $id is a existing classname, return true |
||
257 | * |
||
258 | * @param string $id |
||
259 | * @return bool |
||
260 | * @access protected |
||
261 | */ |
||
262 | protected function autoClassName(/*# string */ $id)/*# : bool */ |
||
270 | } |
||
271 |
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: