1 | <?php |
||
13 | abstract class AbstractElementFactory implements ElementFactory |
||
14 | { |
||
15 | /** |
||
16 | * @var Container |
||
17 | */ |
||
18 | protected $app; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $parameters = []; |
||
24 | |||
25 | /** |
||
26 | * @inheritdoc |
||
27 | */ |
||
28 | 28 | public function __construct(Container $container) |
|
32 | |||
33 | /** |
||
34 | * @param string $class |
||
35 | * @return array |
||
36 | */ |
||
37 | 28 | protected function getElementConfig($class) |
|
41 | |||
42 | /** |
||
43 | * @param string $name |
||
44 | * @return mixed |
||
45 | */ |
||
46 | 9 | protected function getParameter($name) |
|
54 | |||
55 | /** |
||
56 | * @param string $name |
||
57 | * @param mixed $value |
||
58 | * @return $this |
||
59 | */ |
||
60 | 25 | protected function setParameter($name, $value) |
|
66 | |||
67 | /** |
||
68 | * @param string $name |
||
69 | * @return $this |
||
70 | */ |
||
71 | protected function unsetParameter($name) |
||
77 | |||
78 | /** |
||
79 | * @param string $name |
||
80 | * @return bool |
||
81 | */ |
||
82 | protected function existsParameter($name) |
||
86 | |||
87 | /** |
||
88 | * @param array $parameters |
||
89 | * @return array |
||
90 | */ |
||
91 | 27 | protected function mergeParameters($parameters = []) |
|
95 | |||
96 | /** |
||
97 | * @inheritDoc |
||
98 | */ |
||
99 | 9 | function __get($name) |
|
103 | |||
104 | /** |
||
105 | * @inheritDoc |
||
106 | */ |
||
107 | 25 | function __set($name, $value) |
|
111 | |||
112 | /** |
||
113 | * @inheritDoc |
||
114 | */ |
||
115 | function __isset($name) |
||
119 | |||
120 | /** |
||
121 | * @inheritDoc |
||
122 | */ |
||
123 | function __unset($name) |
||
127 | |||
128 | /** |
||
129 | * @inheritDoc |
||
130 | */ |
||
131 | public function toArray() |
||
135 | |||
136 | /** |
||
137 | * @param Element $element |
||
138 | */ |
||
139 | 22 | protected function setDisplayRule(Element $element) |
|
145 | } |
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: