1 | <?php |
||
37 | class AttributeObserver extends AbstractAttributeImportObserver |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The attribute processor instance. |
||
42 | * |
||
43 | * @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface |
||
44 | */ |
||
45 | protected $attributeBunchProcessor; |
||
46 | |||
47 | /** |
||
48 | * Initializes the observer with the passed subject instance. |
||
49 | * |
||
50 | * @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance |
||
51 | */ |
||
52 | public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor) |
||
56 | |||
57 | /** |
||
58 | * Process the observer's business logic. |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | protected function process() |
||
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | protected function getDefaultValues() |
||
89 | |||
90 | /** |
||
91 | * Prepare the attributes of the entity that has to be persisted. |
||
92 | * |
||
93 | * @return array The prepared attributes |
||
94 | */ |
||
95 | protected function prepareAttributes() |
||
127 | |||
128 | /** |
||
129 | * Should default values be used for undefined columns |
||
130 | * @return bool |
||
131 | */ |
||
132 | protected function isForceDefaultValues() |
||
136 | |||
137 | /** |
||
138 | * Initialize the attribute with the passed attributes and returns an instance. |
||
139 | * |
||
140 | * @param array $attr The attribute attributes |
||
141 | * |
||
142 | * @return array The initialized attribute |
||
143 | */ |
||
144 | protected function initializeAttribute(array $attr) |
||
148 | |||
149 | /** |
||
150 | * Return's the attribute bunch processor instance. |
||
151 | * |
||
152 | * @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance |
||
153 | */ |
||
154 | protected function getAttributeBunchProcessor() |
||
158 | |||
159 | /** |
||
160 | * Map's the passed attribute code to the attribute ID that has been created recently. |
||
161 | * |
||
162 | * @param string $attributeCode The attribute code that has to be mapped |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | protected function addAttributeCodeIdMapping($attributeCode) |
||
170 | |||
171 | /** |
||
172 | * Queries whether or not the attribute with the passed code has already been processed. |
||
173 | * |
||
174 | * @param string $attributeCode The attribute code to check |
||
175 | * |
||
176 | * @return boolean TRUE if the path has been processed, else FALSE |
||
177 | */ |
||
178 | protected function hasBeenProcessed($attributeCode) |
||
182 | |||
183 | /** |
||
184 | * Set's the ID of the attribute that has been created recently. |
||
185 | * |
||
186 | * @param integer $lastAttributeId The attribute ID |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | protected function setLastAttributeId($lastAttributeId) |
||
194 | |||
195 | /** |
||
196 | * Persist the passed attribute. |
||
197 | * |
||
198 | * @param array $attribute The attribute to persist |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | protected function persistAttribute(array $attribute) |
||
206 | |||
207 | /** |
||
208 | * Return's the entity type for the passed code. |
||
209 | * |
||
210 | * @param string $entityTypeCode The entity type code |
||
211 | * |
||
212 | * @return array The requested entity type |
||
213 | * @throws \Exception Is thrown, if the entity type with the passed code is not available |
||
214 | */ |
||
215 | protected function getEntityType($entityTypeCode) |
||
219 | } |
||
220 |
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: