1 | <?php |
||
15 | abstract class AbstractElementFactory implements ElementFactory |
||
16 | { |
||
17 | /** |
||
18 | * @var Container |
||
19 | */ |
||
20 | protected $app; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $parameters = []; |
||
26 | |||
27 | /** |
||
28 | * @inheritdoc |
||
29 | */ |
||
30 | 31 | public function __construct(Container $container) |
|
34 | |||
35 | /** |
||
36 | * @param string $class |
||
37 | * @return array |
||
38 | */ |
||
39 | 31 | protected function getElementConfig($class) |
|
43 | |||
44 | /** |
||
45 | * @param string $name |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 12 | protected function getParameter($name) |
|
56 | |||
57 | /** |
||
58 | * @param string $name |
||
59 | * @param mixed $value |
||
60 | * @return $this |
||
61 | */ |
||
62 | 28 | protected function setParameter($name, $value) |
|
68 | |||
69 | /** |
||
70 | * @param string $name |
||
71 | * @return $this |
||
72 | */ |
||
73 | protected function unsetParameter($name) |
||
79 | |||
80 | /** |
||
81 | * @param string $name |
||
82 | * @return bool |
||
83 | */ |
||
84 | protected function existsParameter($name) |
||
88 | |||
89 | /** |
||
90 | * @param array $parameters |
||
91 | * @return array |
||
92 | */ |
||
93 | 20 | protected function mergeParameters($parameters = []) |
|
97 | |||
98 | /** |
||
99 | * @inheritDoc |
||
100 | */ |
||
101 | 12 | function __get($name) |
|
105 | |||
106 | /** |
||
107 | * @inheritDoc |
||
108 | */ |
||
109 | 28 | function __set($name, $value) |
|
113 | |||
114 | /** |
||
115 | * @inheritDoc |
||
116 | */ |
||
117 | function __isset($name) |
||
121 | |||
122 | /** |
||
123 | * @inheritDoc |
||
124 | */ |
||
125 | function __unset($name) |
||
129 | |||
130 | /** |
||
131 | * @inheritDoc |
||
132 | */ |
||
133 | 1 | public function serialize() |
|
142 | |||
143 | /** |
||
144 | * @inheritDoc |
||
145 | */ |
||
146 | 1 | public function unserialize($serialized) |
|
155 | |||
156 | /** |
||
157 | * @inheritDoc |
||
158 | */ |
||
159 | public function toArray() |
||
163 | |||
164 | /** |
||
165 | * @param Element $element |
||
166 | */ |
||
167 | 14 | protected function setDisplayRule(Element $element) |
|
173 | } |
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: