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 | * The array with the possible column names. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $columnNames = array( |
||
52 | ColumnKeys::FRONTEND_INPUT_RENDERER, |
||
53 | ColumnKeys::IS_GLOBAL, |
||
54 | ColumnKeys::IS_VISIBLE, |
||
55 | ColumnKeys::IS_SEARCHABLE, |
||
56 | ColumnKeys::IS_FILTERABLE, |
||
57 | ColumnKeys::IS_COMPARABLE, |
||
58 | ColumnKeys::IS_VISIBLE_ON_FRONT, |
||
59 | ColumnKeys::IS_HTML_ALLOWED_ON_FRONT, |
||
60 | ColumnKeys::IS_USED_FOR_PRICE_RULES, |
||
61 | ColumnKeys::IS_FILTERABLE_IN_SEARCH, |
||
62 | ColumnKeys::USED_IN_PRODUCT_LISTING, |
||
63 | ColumnKeys::USED_FOR_SORT_BY, |
||
64 | ColumnKeys::APPLY_TO, |
||
65 | ColumnKeys::IS_VISIBLE_IN_ADVANCED_SEARCH, |
||
66 | ColumnKeys::POSITION, |
||
67 | ColumnKeys::IS_WYSIWYG_ENABLED, |
||
68 | ColumnKeys::IS_USED_FOR_PROMO_RULES, |
||
69 | ColumnKeys::IS_REQUIRED_IN_ADMIN_STORE, |
||
70 | ColumnKeys::IS_USED_IN_GRID, |
||
71 | ColumnKeys::IS_VISIBLE_IN_GRID, |
||
72 | ColumnKeys::IS_FILTERABLE_IN_GRID, |
||
73 | ColumnKeys::SEARCH_WEIGHT, |
||
74 | ColumnKeys::ADDITIONAL_DATA |
||
75 | ); |
||
76 | |||
77 | /** |
||
78 | * Initializes the observer with the passed subject instance. |
||
79 | * |
||
80 | * @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance |
||
81 | */ |
||
82 | public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor) |
||
86 | |||
87 | /** |
||
88 | * Process the observer's business logic. |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | protected function process() |
||
103 | |||
104 | /** |
||
105 | * Prepare the attributes of the entity that has to be persisted. |
||
106 | * |
||
107 | * @return array The prepared attributes |
||
108 | */ |
||
109 | protected function prepareAttributes() |
||
152 | |||
153 | /** |
||
154 | * Serialize the additional_data attribute of the passed array. |
||
155 | * |
||
156 | * @param array $attr The attribute with the data to serialize |
||
157 | * |
||
158 | * @return array The attribute with the serialized additional_data |
||
159 | */ |
||
160 | protected function serializeAdditionalData(array $attr) |
||
171 | |||
172 | /** |
||
173 | * Initialize the attribute with the passed attributes and returns an instance. |
||
174 | * |
||
175 | * @param array $attr The attribute attributes |
||
176 | * |
||
177 | * @return array The initialized attribute |
||
178 | */ |
||
179 | protected function initializeAttribute(array $attr) |
||
183 | |||
184 | /** |
||
185 | * Return's the attribute bunch processor instance. |
||
186 | * |
||
187 | * @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance |
||
188 | */ |
||
189 | protected function getAttributeBunchProcessor() |
||
193 | |||
194 | /** |
||
195 | * Map's the passed attribute code to the attribute ID that has been created recently. |
||
196 | * |
||
197 | * @param string $attributeCode The attribute code that has to be mapped |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | protected function addAttributeCodeIdMapping($attributeCode) |
||
205 | |||
206 | /** |
||
207 | * Queries whether or not the attribute with the passed code has already been processed. |
||
208 | * |
||
209 | * @param string $attributeCode The attribute code to check |
||
210 | * |
||
211 | * @return boolean TRUE if the path has been processed, else FALSE |
||
212 | */ |
||
213 | protected function hasBeenProcessed($attributeCode) |
||
217 | |||
218 | /** |
||
219 | * Return's the ID of the attribute that has been created recently. |
||
220 | * |
||
221 | * @return integer The attribute ID |
||
222 | */ |
||
223 | protected function getLastAttributeId() |
||
227 | |||
228 | /** |
||
229 | * Persist the passed EAV catalog attribute. |
||
230 | * |
||
231 | * @param array $catalogAttribute The EAV catalog attribute to persist |
||
232 | * |
||
233 | * @return void |
||
234 | */ |
||
235 | protected function persistCatalogAttribute(array $catalogAttribute) |
||
239 | } |
||
240 |
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: