1 | <?php |
||
36 | class CatalogAttributeObserver extends AbstractAttributeImportObserver |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The attribute processor instance. |
||
41 | * |
||
42 | * @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface |
||
43 | */ |
||
44 | protected $attributeBunchProcessor; |
||
45 | |||
46 | /** |
||
47 | * Initializes the observer with the passed subject instance. |
||
48 | * |
||
49 | * @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance |
||
50 | */ |
||
51 | public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor) |
||
55 | |||
56 | /** |
||
57 | * Process the observer's business logic. |
||
58 | * |
||
59 | * @return void |
||
60 | */ |
||
61 | protected function process() |
||
72 | |||
73 | /** |
||
74 | * @return array |
||
75 | */ |
||
76 | protected function getDefaultValues() |
||
102 | |||
103 | /** |
||
104 | * @return array |
||
105 | */ |
||
106 | protected function getCallbacks() |
||
120 | |||
121 | /** |
||
122 | * Prepare the attributes of the entity that has to be persisted. |
||
123 | * |
||
124 | * @return array The prepared attributes |
||
125 | */ |
||
126 | protected function prepareAttributes() |
||
165 | |||
166 | /** |
||
167 | * Should default values be used for undefined columns |
||
168 | * @return bool |
||
169 | */ |
||
170 | protected function isForceDefaultValues() |
||
174 | |||
175 | /** |
||
176 | * Serialize the additional_data attribute of the passed array. |
||
177 | * |
||
178 | * @param array $attr The attribute with the data to serialize |
||
179 | * |
||
180 | * @return array The attribute with the serialized additional_data |
||
181 | */ |
||
182 | protected function serializeAdditionalData(array $attr) |
||
193 | |||
194 | /** |
||
195 | * Initialize the attribute with the passed attributes and returns an instance. |
||
196 | * |
||
197 | * @param array $attr The attribute attributes |
||
198 | * |
||
199 | * @return array The initialized attribute |
||
200 | */ |
||
201 | protected function initializeAttribute(array $attr) |
||
205 | |||
206 | /** |
||
207 | * Return's the attribute bunch processor instance. |
||
208 | * |
||
209 | * @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance |
||
210 | */ |
||
211 | protected function getAttributeBunchProcessor() |
||
215 | |||
216 | /** |
||
217 | * Map's the passed attribute code to the attribute ID that has been created recently. |
||
218 | * |
||
219 | * @param string $attributeCode The attribute code that has to be mapped |
||
220 | * |
||
221 | * @return void |
||
222 | */ |
||
223 | protected function addAttributeCodeIdMapping($attributeCode) |
||
227 | |||
228 | /** |
||
229 | * Queries whether or not the attribute with the passed code has already been processed. |
||
230 | * |
||
231 | * @param string $attributeCode The attribute code to check |
||
232 | * |
||
233 | * @return boolean TRUE if the path has been processed, else FALSE |
||
234 | */ |
||
235 | protected function hasBeenProcessed($attributeCode) |
||
239 | |||
240 | /** |
||
241 | * Return's the ID of the attribute that has been created recently. |
||
242 | * |
||
243 | * @return integer The attribute ID |
||
244 | */ |
||
245 | protected function getLastAttributeId() |
||
249 | |||
250 | /** |
||
251 | * Persist the passed EAV catalog attribute. |
||
252 | * |
||
253 | * @param array $catalogAttribute The EAV catalog attribute to persist |
||
254 | * |
||
255 | * @return void |
||
256 | */ |
||
257 | protected function persistCatalogAttribute(array $catalogAttribute) |
||
261 | } |
||
262 |
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: