1 | <?php |
||
13 | class DriverLocator |
||
14 | { |
||
15 | /** |
||
16 | * @var DriverClassNameResolver |
||
17 | */ |
||
18 | private $classNameResolver; |
||
19 | |||
20 | /** |
||
21 | * @var DriverInterface[] |
||
22 | */ |
||
23 | private $drivers = []; |
||
24 | |||
25 | /** |
||
26 | * @param DriverClassNameResolver $classNameResolver |
||
27 | */ |
||
28 | public function __construct(DriverClassNameResolver $classNameResolver) |
||
32 | |||
33 | /** |
||
34 | * @param string $namespace |
||
35 | * @param string $parent |
||
36 | * |
||
37 | * @return Locator |
||
38 | */ |
||
39 | public static function getInstance($namespace, $parent = '') |
||
43 | |||
44 | /** |
||
45 | * @param ContainerBuilder $container |
||
46 | * @param array $activeDrivers |
||
47 | * @param array $driverConfigs |
||
48 | * |
||
49 | * @return DriverInterface[] |
||
50 | */ |
||
51 | public function findDrivers(ContainerBuilder $container, array $activeDrivers, array $driverConfigs) |
||
61 | |||
62 | /** |
||
63 | * @return DriverInterface[] |
||
64 | */ |
||
65 | public function getDrivers() |
||
69 | |||
70 | /** |
||
71 | * @param array $activeDrivers |
||
72 | * @param array $driverConfigs |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | private function removeUnusedDrivers($activeDrivers, $driverConfigs) |
||
86 | |||
87 | /** |
||
88 | * @param array $driverKeys |
||
89 | * |
||
90 | * @return DriverInterface[] |
||
91 | */ |
||
92 | private function createDrivers($driverKeys) |
||
103 | |||
104 | /** |
||
105 | * @return NodeInterface |
||
106 | */ |
||
107 | private function configureDrivers() |
||
117 | |||
118 | /** |
||
119 | * @param NodeInterface $configTree |
||
120 | * @param array $configs |
||
121 | * |
||
122 | * @return array The processed configuration |
||
123 | */ |
||
124 | private function processDriverConfiguration(NodeInterface $configTree, array $configs) |
||
134 | |||
135 | /** |
||
136 | * @param ContainerBuilder $container |
||
137 | * @param array $driverConfigs |
||
138 | * |
||
139 | * @return DriverInterface[] |
||
140 | */ |
||
141 | private function loadDrivers(ContainerBuilder $container, array $driverConfigs) |
||
149 | } |
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 sub-classes 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 parent class: