1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Attribute\Set\Observers\AbstractAttributeSetObserver |
5
|
|
|
* |
6
|
|
|
* PHP version 7 |
7
|
|
|
* |
8
|
|
|
* @author Tim Wagner <[email protected]> |
9
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @link https://github.com/techdivision/import-attribute-set |
12
|
|
|
* @link http://www.techdivision.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Attribute\Set\Observers; |
16
|
|
|
|
17
|
|
|
use TechDivision\Import\Subjects\SubjectInterface; |
18
|
|
|
use TechDivision\Import\Observers\AbstractObserver; |
19
|
|
|
use TechDivision\Import\Attribute\Set\Services\AttributeSetBunchProcessorInterface; |
20
|
|
|
use TechDivision\Import\Observers\StateDetectorInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Abstract attribute observer that handles the process to import attribute set bunches. |
24
|
|
|
* |
25
|
|
|
* @author Tim Wagner <[email protected]> |
26
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
27
|
|
|
* @license https://opensource.org/licenses/MIT |
28
|
|
|
* @link https://github.com/techdivision/import-attribute-set |
29
|
|
|
* @link http://www.techdivision.com |
30
|
|
|
*/ |
31
|
|
|
abstract class AbstractAttributeSetObserver extends AbstractObserver |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The attribute set bunch processor instance. |
36
|
|
|
* |
37
|
|
|
* @var \TechDivision\Import\Attribute\Set\Services\AttributeSetBunchProcessorInterface |
38
|
|
|
*/ |
39
|
|
|
protected $attributeSetBunchProcessor; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Initializes the observer with the passed subject instance. |
43
|
|
|
* |
44
|
|
|
* @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeSetBunchProcessor The attribute set bunch processor instance |
45
|
|
|
* @param \TechDivision\Import\Observers\StateDetectorInterface|null $stateDetector The state detector instance to use |
46
|
|
|
*/ |
47
|
|
|
public function __construct(AttributeSetBunchProcessorInterface $attributeSetBunchProcessor, StateDetectorInterface $stateDetector = null) |
48
|
|
|
{ |
49
|
|
|
|
50
|
|
|
// set the attribute set bunch processor instance |
51
|
|
|
$this->attributeSetBunchProcessor = $attributeSetBunchProcessor; |
52
|
|
|
|
53
|
|
|
// pass the state detector to the parent constructor |
54
|
|
|
parent::__construct($stateDetector); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return's the attribute set bunch processor instance. |
59
|
|
|
* |
60
|
|
|
* @return \TechDivision\Import\Attribute\Set\Services\AttributeSetBunchProcessorInterface The attribute set bunch processor instance |
61
|
|
|
*/ |
62
|
|
|
protected function getAttributeSetBunchProcessor() |
63
|
|
|
{ |
64
|
|
|
return $this->attributeSetBunchProcessor; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Will be invoked by the action on the events the listener has been registered for. |
69
|
|
|
* |
70
|
|
|
* @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance |
71
|
|
|
* |
72
|
|
|
* @return array The modified row |
73
|
|
|
* @see \TechDivision\Import\Observers\ObserverInterface::handle() |
74
|
|
|
*/ |
75
|
|
|
public function handle(SubjectInterface $subject) |
76
|
|
|
{ |
77
|
|
|
|
78
|
|
|
// initialize the row |
79
|
|
|
$this->setSubject($subject); |
80
|
|
|
$this->setRow($subject->getRow()); |
81
|
|
|
|
82
|
|
|
// process the functionality and return the row |
83
|
|
|
$this->process(); |
84
|
|
|
|
85
|
|
|
// return the processed row |
86
|
|
|
return $this->getRow(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Queries whether or not the attribute set with the passed entity type code and attribute set |
91
|
|
|
* name has already been processed. |
92
|
|
|
* |
93
|
|
|
* @param string $entityTypeCode The entity type code to check |
94
|
|
|
* @param string $attributeSetName The attribute set name to check |
95
|
|
|
* |
96
|
|
|
* @return boolean TRUE if the attribute set has been processed, else FALSE |
97
|
|
|
*/ |
98
|
|
|
protected function hasBeenProcessed($entityTypeCode, $attributeSetName) |
99
|
|
|
{ |
100
|
|
|
return $this->getSubject()->hasBeenProcessed($entityTypeCode, $attributeSetName); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Set's the attribute set that has been created recently. |
105
|
|
|
* |
106
|
|
|
* @param array $lastAttributeSet The attribute set |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
protected function setLastAttributeSet(array $lastAttributeSet) |
111
|
|
|
{ |
112
|
|
|
$this->getSubject()->setLastAttributeSet($lastAttributeSet); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Return's the attribute set that has been created recently. |
117
|
|
|
* |
118
|
|
|
* @return array The attribute set |
119
|
|
|
*/ |
120
|
|
|
protected function getLastAttributeSet() |
121
|
|
|
{ |
122
|
|
|
return $this->getSubject()->getLastAttributeSet(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Process the observer's business logic. |
127
|
|
|
* |
128
|
|
|
* @return void |
129
|
|
|
*/ |
130
|
|
|
abstract protected function process(); |
131
|
|
|
} |
132
|
|
|
|