1 | <?php |
||
39 | trait AttributeObserverTrait |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * The ID of the attribute to create the values for. |
||
44 | * |
||
45 | * @var integer |
||
46 | */ |
||
47 | protected $attributeId; |
||
48 | |||
49 | /** |
||
50 | * The attribute code of the attribute to create the values for. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $attributeCode; |
||
55 | |||
56 | /** |
||
57 | * The backend type of the attribute to create the values for. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $backendType; |
||
62 | |||
63 | /** |
||
64 | * The attribute value to process. |
||
65 | * |
||
66 | * @var mixed |
||
67 | */ |
||
68 | protected $attributeValue; |
||
69 | |||
70 | /** |
||
71 | * The array with the column keys that has to be cleaned up when their values are empty. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $cleanUpEmptyColumnKeys; |
||
76 | |||
77 | /** |
||
78 | * The entity's existing attribues. |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | protected $attributes; |
||
83 | |||
84 | /** |
||
85 | * The attribute code that has to be processed. |
||
86 | * |
||
87 | * @return string The attribute code |
||
88 | */ |
||
89 | 1 | public function getAttributeCode() |
|
93 | |||
94 | /** |
||
95 | * The attribute value that has to be processed. |
||
96 | * |
||
97 | * @return string The attribute value |
||
98 | */ |
||
99 | 1 | public function getAttributeValue() |
|
103 | |||
104 | /** |
||
105 | * Remove all the empty values from the row and return the cleared row. |
||
106 | * |
||
107 | * @return array The cleared row |
||
108 | */ |
||
109 | 7 | protected function clearRow() |
|
140 | |||
141 | /** |
||
142 | * Returns the value(s) of the primary key column(s). As the primary key column can |
||
143 | * also consist of two columns, the return value can be an array also. |
||
144 | * |
||
145 | * @return mixed The primary key value(s) |
||
146 | */ |
||
147 | 7 | protected function getPrimaryKeyValue() |
|
151 | |||
152 | /** |
||
153 | * Process the observer's business logic. |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | 7 | protected function process() |
|
301 | |||
302 | /** |
||
303 | * Prepare the attributes of the entity that has to be persisted. |
||
304 | * |
||
305 | * @return array|null The prepared attributes |
||
306 | */ |
||
307 | 2 | protected function prepareAttributes() |
|
337 | |||
338 | /** |
||
339 | * Initialize the category product with the passed attributes and returns an instance. |
||
340 | * |
||
341 | * @param array $attr The category product attributes |
||
342 | * |
||
343 | * @return array The initialized category product |
||
344 | */ |
||
345 | 2 | protected function initializeAttribute(array $attr) |
|
349 | |||
350 | /** |
||
351 | * Return's the array with callbacks for the passed type. |
||
352 | * |
||
353 | * @param string $type The type of the callbacks to return |
||
354 | * |
||
355 | * @return array The callbacks |
||
356 | */ |
||
357 | 2 | protected function getCallbacksByType($type) |
|
361 | |||
362 | /** |
||
363 | * Return's mapping for the supported backend types (for the product entity) => persist methods. |
||
364 | * |
||
365 | * @return array The mapping for the supported backend types |
||
366 | */ |
||
367 | 7 | protected function getBackendTypes() |
|
371 | |||
372 | /** |
||
373 | * Return's the attributes for the attribute set of the product that has to be created. |
||
374 | * |
||
375 | * @return array The attributes |
||
376 | * @throws \Exception |
||
377 | */ |
||
378 | 7 | protected function getAttributes() |
|
382 | |||
383 | /** |
||
384 | * Intializes the existing attributes for the entity with the passed primary key. |
||
385 | * |
||
386 | * @param string $pk The primary key of the entity to load the attributes for |
||
387 | * @param integer $storeId The ID of the store view to load the attributes for |
||
388 | * |
||
389 | * @return array The entity attributes |
||
390 | */ |
||
391 | abstract protected function getAttributesByPrimaryKeyAndStoreId($pk, $storeId); |
||
392 | |||
393 | /** |
||
394 | * Return's the logger with the passed name, by default the system logger. |
||
395 | * |
||
396 | * @param string $name The name of the requested system logger |
||
397 | * |
||
398 | * @return \Psr\Log\LoggerInterface The logger instance |
||
399 | * @throws \Exception Is thrown, if the requested logger is NOT available |
||
400 | */ |
||
401 | abstract protected function getSystemLogger($name = LoggerKeys::SYSTEM); |
||
402 | |||
403 | /** |
||
404 | * Return's the PK to create the product => attribute relation. |
||
405 | * |
||
406 | * @return integer The PK to create the relation with |
||
407 | */ |
||
408 | abstract protected function getPrimaryKey(); |
||
409 | |||
410 | /** |
||
411 | * Return's the PK column name to create the product => attribute relation. |
||
412 | * |
||
413 | * @return string The PK column name |
||
414 | */ |
||
415 | abstract protected function getPrimaryKeyMemberName(); |
||
416 | |||
417 | /** |
||
418 | * Return's the column name that contains the primary key. |
||
419 | * |
||
420 | * @return string the column name that contains the primary key |
||
421 | */ |
||
422 | abstract protected function getPrimaryKeyColumnName(); |
||
423 | |||
424 | /** |
||
425 | * Queries whether or not the passed PK and store view code has already been processed. |
||
426 | * |
||
427 | * @param string $pk The PK to check been processed |
||
428 | * @param string $storeViewCode The store view code to check been processed |
||
429 | * |
||
430 | * @return boolean TRUE if the PK and store view code has been processed, else FALSE |
||
431 | */ |
||
432 | abstract protected function storeViewHasBeenProcessed($pk, $storeViewCode); |
||
433 | |||
434 | /** |
||
435 | * Persist's the passed varchar attribute. |
||
436 | * |
||
437 | * @param array $attribute The attribute to persist |
||
438 | * |
||
439 | * @return void |
||
440 | */ |
||
441 | abstract protected function persistVarcharAttribute($attribute); |
||
442 | |||
443 | /** |
||
444 | * Persist's the passed integer attribute. |
||
445 | * |
||
446 | * @param array $attribute The attribute to persist |
||
447 | * |
||
448 | * @return void |
||
449 | */ |
||
450 | abstract protected function persistIntAttribute($attribute); |
||
451 | |||
452 | /** |
||
453 | * Persist's the passed decimal attribute. |
||
454 | * |
||
455 | * @param array $attribute The attribute to persist |
||
456 | * |
||
457 | * @return void |
||
458 | */ |
||
459 | abstract protected function persistDecimalAttribute($attribute); |
||
460 | |||
461 | /** |
||
462 | * Persist's the passed datetime attribute. |
||
463 | * |
||
464 | * @param array $attribute The attribute to persist |
||
465 | * |
||
466 | * @return void |
||
467 | */ |
||
468 | abstract protected function persistDatetimeAttribute($attribute); |
||
469 | |||
470 | /** |
||
471 | * Persist's the passed text attribute. |
||
472 | * |
||
473 | * @param array $attribute The attribute to persist |
||
474 | * |
||
475 | * @return void |
||
476 | */ |
||
477 | abstract protected function persistTextAttribute($attribute); |
||
478 | |||
479 | /** |
||
480 | * Delete's the datetime attribute with the passed value ID. |
||
481 | * |
||
482 | * @param array $row The attributes of the entity to delete |
||
483 | * @param string|null $name The name of the prepared statement that has to be executed |
||
484 | * |
||
485 | * @return void |
||
486 | */ |
||
487 | abstract protected function deleteDatetimeAttribute(array $row, $name = null); |
||
488 | |||
489 | /** |
||
490 | * Delete's the decimal attribute with the passed value ID. |
||
491 | * |
||
492 | * @param array $row The attributes of the entity to delete |
||
493 | * @param string|null $name The name of the prepared statement that has to be executed |
||
494 | * |
||
495 | * @return void |
||
496 | */ |
||
497 | abstract protected function deleteDecimalAttribute(array $row, $name = null); |
||
498 | |||
499 | /** |
||
500 | * Delete's the integer attribute with the passed value ID. |
||
501 | * |
||
502 | * @param array $row The attributes of the entity to delete |
||
503 | * @param string|null $name The name of the prepared statement that has to be executed |
||
504 | * |
||
505 | * @return void |
||
506 | */ |
||
507 | abstract protected function deleteIntAttribute(array $row, $name = null); |
||
508 | |||
509 | /** |
||
510 | * Delete's the text attribute with the passed value ID. |
||
511 | * |
||
512 | * @param array $row The attributes of the entity to delete |
||
513 | * @param string|null $name The name of the prepared statement that has to be executed |
||
514 | * |
||
515 | * @return void |
||
516 | */ |
||
517 | abstract protected function deleteTextAttribute(array $row, $name = null); |
||
518 | |||
519 | /** |
||
520 | * Delete's the varchar attribute with the passed value ID. |
||
521 | * |
||
522 | * @param array $row The attributes of the entity to delete |
||
523 | * @param string|null $name The name of the prepared statement that has to be executed |
||
524 | * |
||
525 | * @return void |
||
526 | */ |
||
527 | abstract protected function deleteVarcharAttribute(array $row, $name = null); |
||
528 | } |
||
529 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.