1 | <?php |
||
37 | class UrlRewriteObserver extends AbstractCategoryImportObserver |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The entity type to load the URL rewrites for. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | const ENTITY_TYPE = 'category'; |
||
46 | |||
47 | /** |
||
48 | * The processor to read/write the necessary category data. |
||
49 | * |
||
50 | * @var \TechDivision\Import\Category\Services\CategoryBunchProcessorInterface |
||
51 | */ |
||
52 | protected $categoryBunchProcessor; |
||
53 | |||
54 | /** |
||
55 | * Initialize the subject instance. |
||
56 | * |
||
57 | * @param \TechDivision\Import\Category\Services\CategoryBunchProcessorInterface $categoryBunchProcessor The category bunch processor instance |
||
58 | */ |
||
59 | public function __construct(CategoryBunchProcessorInterface $categoryBunchProcessor) |
||
63 | |||
64 | /** |
||
65 | * Return's the category bunch processor instance. |
||
66 | * |
||
67 | * @return \TechDivision\Import\Category\Services\CategoryBunchProcessorInterface The category bunch processor instance |
||
68 | */ |
||
69 | protected function getCategoryBunchProcessor() |
||
73 | |||
74 | /** |
||
75 | * Process the observer's business logic. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | protected function process() |
||
108 | |||
109 | /** |
||
110 | * Initialize the URL rewrite with the passed attributes and returns an instance. |
||
111 | * |
||
112 | * @param array $attr The URL rewrite attributes |
||
113 | * |
||
114 | * @return array The initialized URL rewrite |
||
115 | */ |
||
116 | protected function initializeUrlRewrite(array $attr) |
||
120 | |||
121 | /** |
||
122 | * Prepare's the URL rewrites that has to be created/updated. |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | protected function prepareUrlRewrites() |
||
130 | |||
131 | /** |
||
132 | * Prepare the attributes of the entity that has to be persisted. |
||
133 | * |
||
134 | * @return array The prepared attributes |
||
135 | */ |
||
136 | protected function prepareAttributes() |
||
162 | |||
163 | /** |
||
164 | * Prepare's the target path for a URL rewrite. |
||
165 | * |
||
166 | * @return string The target path |
||
167 | */ |
||
168 | protected function prepareTargetPath() |
||
172 | |||
173 | /** |
||
174 | * Prepare's the request path for a URL rewrite or the target path for a 301 redirect. |
||
175 | * |
||
176 | * @return string The request path |
||
177 | */ |
||
178 | protected function prepareRequestPath() |
||
187 | |||
188 | /** |
||
189 | * Set's the ID of the product that has been created recently. |
||
190 | * |
||
191 | * @param string $lastEntityId The entity ID |
||
192 | * |
||
193 | * @return void |
||
194 | */ |
||
195 | protected function setLastEntityId($lastEntityId) |
||
199 | |||
200 | /** |
||
201 | * Return's the store ID of the actual row, or of the default store |
||
202 | * if no store view code is set in the CSV file. |
||
203 | * |
||
204 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
205 | * |
||
206 | * @return integer The ID of the actual store |
||
207 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
208 | */ |
||
209 | protected function getRowStoreId($default = null) |
||
213 | |||
214 | /** |
||
215 | * Persist's the URL rewrite with the passed data. |
||
216 | * |
||
217 | * @param array $row The URL rewrite to persist |
||
218 | * |
||
219 | * @return string The ID of the persisted entity |
||
220 | */ |
||
221 | protected function persistUrlRewrite($row) |
||
225 | |||
226 | /** |
||
227 | * Return's the PK to create the product => attribute relation. |
||
228 | * |
||
229 | * @return integer The PK to create the relation with |
||
230 | */ |
||
231 | protected function getPrimaryKey() |
||
235 | } |
||
236 |
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: