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 $resetManagers = []; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $defaultManagerName; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | private $proxyInterfaceName; |
||
53 | |||
54 | /** |
||
55 | * @param Container $container |
||
56 | * @param string $proxyInterfaceName |
||
57 | */ |
||
58 | 10 | public function __construct(Container $container, $proxyInterfaceName = Proxy::class) |
|
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | 3 | public function getDefaultConnectionName(): string |
|
73 | |||
74 | /** |
||
75 | * @param string|null $name |
||
76 | * |
||
77 | * @return Connection |
||
78 | * |
||
79 | * @throws \InvalidArgumentException |
||
80 | */ |
||
81 | 2 | public function getConnection($name = null): Connection |
|
93 | |||
94 | /** |
||
95 | * @return Connection[] |
||
96 | */ |
||
97 | 1 | public function getConnections(): array |
|
108 | |||
109 | /** |
||
110 | * @return string[] |
||
111 | */ |
||
112 | 1 | public function getConnectionNames(): array |
|
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | 3 | public function getDefaultManagerName(): string |
|
128 | |||
129 | /** |
||
130 | * @param string|null $name |
||
131 | * |
||
132 | * @return EntityManager|ObjectManager |
||
133 | */ |
||
134 | 2 | public function getManager($name = null): ObjectManager |
|
150 | |||
151 | /** |
||
152 | * @return EntityManager[]|ObjectManager[] |
||
153 | */ |
||
154 | 1 | public function getManagers(): array |
|
171 | |||
172 | /** |
||
173 | * @return array |
||
174 | */ |
||
175 | 1 | public function getManagerNames(): array |
|
181 | |||
182 | /** |
||
183 | * @param string|null $name |
||
184 | * |
||
185 | * @return EntityManager|ObjectManager |
||
186 | */ |
||
187 | public function resetManager($name = null) |
||
207 | |||
208 | /** |
||
209 | * @param string $alias |
||
210 | * |
||
211 | * @return string |
||
212 | * |
||
213 | * @throws ORMException |
||
214 | */ |
||
215 | public function getAliasNamespace($alias): string |
||
226 | |||
227 | /** |
||
228 | * @param string $persistentObject |
||
229 | * @param null $persistentManagerName |
||
230 | * |
||
231 | * @return EntityRepository|ObjectRepository |
||
232 | */ |
||
233 | public function getRepository($persistentObject, $persistentManagerName = null): ObjectRepository |
||
237 | |||
238 | /** |
||
239 | * @param string $class |
||
240 | * |
||
241 | * @return EntityManager|ObjectManager|null |
||
242 | */ |
||
243 | public function getManagerForClass($class) |
||
256 | |||
257 | 5 | private function loadConnections() |
|
264 | |||
265 | 5 | private function loadManagers() |
|
272 | } |
||
273 |
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: