Passed
Pull Request — master (#1)
by Tim
03:10
created

setLastAttributeSetId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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