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() |
|
142 | |||
143 | /** |
||
144 | * Returns the value(s) of the primary key column(s). As the primary key column can |
||
145 | * also consist of two columns, the return value can be an array also. |
||
146 | * |
||
147 | * @return mixed The primary key value(s) |
||
148 | */ |
||
149 | 7 | protected function getPrimaryKeyValue() |
|
153 | |||
154 | /** |
||
155 | * Process the observer's business logic. |
||
156 | * |
||
157 | * @return void |
||
158 | */ |
||
159 | 7 | protected function process() |
|
305 | |||
306 | /** |
||
307 | * Prepare the attributes of the entity that has to be persisted. |
||
308 | * |
||
309 | * @return array|null The prepared attributes |
||
310 | */ |
||
311 | 2 | protected function prepareAttributes() |
|
341 | |||
342 | /** |
||
343 | * Initialize the category product with the passed attributes and returns an instance. |
||
344 | * |
||
345 | * @param array $attr The category product attributes |
||
346 | * |
||
347 | * @return array The initialized category product |
||
348 | */ |
||
349 | 2 | protected function initializeAttribute(array $attr) |
|
353 | |||
354 | /** |
||
355 | * Return's the array with callbacks for the passed type. |
||
356 | * |
||
357 | * @param string $type The type of the callbacks to return |
||
358 | * |
||
359 | * @return array The callbacks |
||
360 | */ |
||
361 | 2 | protected function getCallbacksByType($type) |
|
365 | |||
366 | /** |
||
367 | * Return's mapping for the supported backend types (for the product entity) => persist methods. |
||
368 | * |
||
369 | * @return array The mapping for the supported backend types |
||
370 | */ |
||
371 | 7 | protected function getBackendTypes() |
|
375 | |||
376 | /** |
||
377 | * Return's the attributes for the attribute set of the product that has to be created. |
||
378 | * |
||
379 | * @return array The attributes |
||
380 | * @throws \Exception |
||
381 | */ |
||
382 | 7 | protected function getAttributes() |
|
386 | |||
387 | /** |
||
388 | * Intializes the existing attributes for the entity with the passed primary key. |
||
389 | * |
||
390 | * @param string $pk The primary key of the entity to load the attributes for |
||
391 | * @param integer $storeId The ID of the store view to load the attributes for |
||
392 | * |
||
393 | * @return array The entity attributes |
||
394 | */ |
||
395 | abstract protected function getAttributesByPrimaryKeyAndStoreId($pk, $storeId); |
||
396 | |||
397 | /** |
||
398 | * Return's the logger with the passed name, by default the system logger. |
||
399 | * |
||
400 | * @param string $name The name of the requested system logger |
||
401 | * |
||
402 | * @return \Psr\Log\LoggerInterface The logger instance |
||
403 | * @throws \Exception Is thrown, if the requested logger is NOT available |
||
404 | */ |
||
405 | abstract protected function getSystemLogger($name = LoggerKeys::SYSTEM); |
||
406 | |||
407 | /** |
||
408 | * Return's the PK to create the product => attribute relation. |
||
409 | * |
||
410 | * @return integer The PK to create the relation with |
||
411 | */ |
||
412 | abstract protected function getPrimaryKey(); |
||
413 | |||
414 | /** |
||
415 | * Return's the PK column name to create the product => attribute relation. |
||
416 | * |
||
417 | * @return string The PK column name |
||
418 | */ |
||
419 | abstract protected function getPrimaryKeyMemberName(); |
||
420 | |||
421 | /** |
||
422 | * Return's the column name that contains the primary key. |
||
423 | * |
||
424 | * @return string the column name that contains the primary key |
||
425 | */ |
||
426 | abstract protected function getPrimaryKeyColumnName(); |
||
427 | |||
428 | /** |
||
429 | * Queries whether or not the passed PK and store view code has already been processed. |
||
430 | * |
||
431 | * @param string $pk The PK to check been processed |
||
432 | * @param string $storeViewCode The store view code to check been processed |
||
433 | * |
||
434 | * @return boolean TRUE if the PK and store view code has been processed, else FALSE |
||
435 | */ |
||
436 | abstract protected function storeViewHasBeenProcessed($pk, $storeViewCode); |
||
437 | |||
438 | /** |
||
439 | * Persist's the passed varchar attribute. |
||
440 | * |
||
441 | * @param array $attribute The attribute to persist |
||
442 | * |
||
443 | * @return void |
||
444 | */ |
||
445 | abstract protected function persistVarcharAttribute($attribute); |
||
446 | |||
447 | /** |
||
448 | * Persist's the passed integer attribute. |
||
449 | * |
||
450 | * @param array $attribute The attribute to persist |
||
451 | * |
||
452 | * @return void |
||
453 | */ |
||
454 | abstract protected function persistIntAttribute($attribute); |
||
455 | |||
456 | /** |
||
457 | * Persist's the passed decimal attribute. |
||
458 | * |
||
459 | * @param array $attribute The attribute to persist |
||
460 | * |
||
461 | * @return void |
||
462 | */ |
||
463 | abstract protected function persistDecimalAttribute($attribute); |
||
464 | |||
465 | /** |
||
466 | * Persist's the passed datetime attribute. |
||
467 | * |
||
468 | * @param array $attribute The attribute to persist |
||
469 | * |
||
470 | * @return void |
||
471 | */ |
||
472 | abstract protected function persistDatetimeAttribute($attribute); |
||
473 | |||
474 | /** |
||
475 | * Persist's the passed text attribute. |
||
476 | * |
||
477 | * @param array $attribute The attribute to persist |
||
478 | * |
||
479 | * @return void |
||
480 | */ |
||
481 | abstract protected function persistTextAttribute($attribute); |
||
482 | |||
483 | /** |
||
484 | * Delete's the datetime attribute with the passed value ID. |
||
485 | * |
||
486 | * @param array $row The attributes of the entity to delete |
||
487 | * @param string|null $name The name of the prepared statement that has to be executed |
||
488 | * |
||
489 | * @return void |
||
490 | */ |
||
491 | abstract protected function deleteDatetimeAttribute(array $row, $name = null); |
||
492 | |||
493 | /** |
||
494 | * Delete's the decimal attribute with the passed value ID. |
||
495 | * |
||
496 | * @param array $row The attributes of the entity to delete |
||
497 | * @param string|null $name The name of the prepared statement that has to be executed |
||
498 | * |
||
499 | * @return void |
||
500 | */ |
||
501 | abstract protected function deleteDecimalAttribute(array $row, $name = null); |
||
502 | |||
503 | /** |
||
504 | * Delete's the integer attribute with the passed value ID. |
||
505 | * |
||
506 | * @param array $row The attributes of the entity to delete |
||
507 | * @param string|null $name The name of the prepared statement that has to be executed |
||
508 | * |
||
509 | * @return void |
||
510 | */ |
||
511 | abstract protected function deleteIntAttribute(array $row, $name = null); |
||
512 | |||
513 | /** |
||
514 | * Delete's the text attribute with the passed value ID. |
||
515 | * |
||
516 | * @param array $row The attributes of the entity to delete |
||
517 | * @param string|null $name The name of the prepared statement that has to be executed |
||
518 | * |
||
519 | * @return void |
||
520 | */ |
||
521 | abstract protected function deleteTextAttribute(array $row, $name = null); |
||
522 | |||
523 | /** |
||
524 | * Delete's the varchar attribute with the passed value ID. |
||
525 | * |
||
526 | * @param array $row The attributes of the entity to delete |
||
527 | * @param string|null $name The name of the prepared statement that has to be executed |
||
528 | * |
||
529 | * @return void |
||
530 | */ |
||
531 | abstract protected function deleteVarcharAttribute(array $row, $name = null); |
||
532 | } |
||
533 |
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.