1 | <?php |
||
17 | final class DoctrineOrmManagerRegistry implements ManagerRegistry |
||
18 | { |
||
19 | /** |
||
20 | * @var Container |
||
21 | */ |
||
22 | private $container; |
||
23 | |||
24 | /** |
||
25 | * @var Container|Connection[] |
||
26 | */ |
||
27 | private $connections; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $defaultConnectionName; |
||
33 | |||
34 | /** |
||
35 | * @var Container|EntityManager[] |
||
36 | */ |
||
37 | private $originalManagers; |
||
38 | |||
39 | /** |
||
40 | * @var EntityManager[] |
||
41 | */ |
||
42 | private $resetedManagers = []; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $defaultManagerName; |
||
48 | |||
49 | /** |
||
50 | * @param Container $container |
||
51 | */ |
||
52 | 17 | public function __construct(Container $container) |
|
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | 3 | public function getDefaultConnectionName(): string |
|
66 | |||
67 | /** |
||
68 | * @param string|null $name |
||
69 | * |
||
70 | * @return Connection |
||
71 | * |
||
72 | * @throws \InvalidArgumentException |
||
73 | */ |
||
74 | 2 | public function getConnection($name = null): Connection |
|
86 | |||
87 | /** |
||
88 | * @return Connection[] |
||
89 | */ |
||
90 | 1 | public function getConnections(): array |
|
101 | |||
102 | /** |
||
103 | * @return string[] |
||
104 | */ |
||
105 | 1 | public function getConnectionNames(): array |
|
111 | |||
112 | /** |
||
113 | * @return string |
||
114 | */ |
||
115 | 6 | public function getDefaultManagerName(): string |
|
121 | |||
122 | /** |
||
123 | * @param string|null $name |
||
124 | * |
||
125 | * @return EntityManager|ObjectManager |
||
126 | */ |
||
127 | 6 | public function getManager($name = null): ObjectManager |
|
143 | |||
144 | /** |
||
145 | * @return EntityManager[]|ObjectManager[] |
||
146 | */ |
||
147 | 2 | public function getManagers(): array |
|
164 | |||
165 | /** |
||
166 | * @return array |
||
167 | */ |
||
168 | 3 | public function getManagerNames(): array |
|
174 | |||
175 | /** |
||
176 | * @param string|null $name |
||
177 | * |
||
178 | * @return EntityManager|ObjectManager |
||
179 | */ |
||
180 | 2 | public function resetManager($name = null) |
|
200 | |||
201 | /** |
||
202 | * @param string $alias |
||
203 | * |
||
204 | * @return string |
||
205 | * |
||
206 | * @throws ORMException |
||
207 | */ |
||
208 | 2 | public function getAliasNamespace($alias): string |
|
219 | |||
220 | /** |
||
221 | * @param string $persistentObject |
||
222 | * @param null $persistentManagerName |
||
223 | * |
||
224 | * @return EntityRepository|ObjectRepository |
||
225 | */ |
||
226 | 1 | public function getRepository($persistentObject, $persistentManagerName = null): ObjectRepository |
|
230 | |||
231 | /** |
||
232 | * @param string $class |
||
233 | * |
||
234 | * @return EntityManager|ObjectManager|null |
||
235 | */ |
||
236 | public function getManagerForClass($class) |
||
249 | |||
250 | 5 | private function loadConnections() |
|
257 | |||
258 | 12 | private function loadManagers() |
|
265 | } |
||
266 |
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: