|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Observers\GenericColumnCollectorObserver |
|
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 |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use Ramsey\Uuid\Uuid; |
|
24
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
|
25
|
|
|
use TechDivision\Import\Loaders\LoaderInterface; |
|
26
|
|
|
use TechDivision\Import\Subjects\SubjectInterface; |
|
27
|
|
|
use TechDivision\Import\Services\RegistryProcessorInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Observer that loads configurable data into the registry. |
|
31
|
|
|
* |
|
32
|
|
|
* @author Tim Wagner <[email protected]> |
|
33
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
34
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
35
|
|
|
* @link https://github.com/techdivision/import |
|
36
|
|
|
* @link http://www.techdivision.com |
|
37
|
|
|
*/ |
|
38
|
|
|
class GenericColumnCollectorObserver extends AbstractObserver |
|
39
|
|
|
{ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The loader instance for the custom validations. |
|
43
|
|
|
* |
|
44
|
|
|
* @var \TechDivision\Import\Loaders\LoaderInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $loader; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The registry processor instance. |
|
50
|
|
|
* |
|
51
|
|
|
* @var \TechDivision\Import\Services\RegistryProcessorInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $registryProcessor; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Initializes the callback with the loader instance. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \TechDivision\Import\Loaders\LoaderInterface $loader The loader for the validations |
|
59
|
|
|
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance |
|
60
|
|
|
*/ |
|
61
|
|
|
public function __construct(LoaderInterface $loader, RegistryProcessorInterface $registryProcessor) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->loader = $loader; |
|
64
|
|
|
$this->registryProcessor = $registryProcessor; |
|
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
|
|
|
* Return's the loader instance for the custom validations. |
|
91
|
|
|
* |
|
92
|
|
|
* @return \TechDivision\Import\Loaders\LoaderInterface The loader instance |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function getLoader() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->loader; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Return's the registry processor instance. |
|
101
|
|
|
* |
|
102
|
|
|
* @return \TechDivision\Import\Services\RegistryProcessorInterface The processor instance |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function getRegistryProcessor() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->registryProcessor; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Process the observer's business logic. |
|
111
|
|
|
* |
|
112
|
|
|
* @return array The processed row |
|
113
|
|
|
* @throws \Exception Is thrown, if the product with the SKU can not be loaded |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function process() |
|
116
|
|
|
{ |
|
117
|
|
|
|
|
118
|
|
|
// initialize the array for the column values |
|
119
|
|
|
$values = array(); |
|
120
|
|
|
|
|
121
|
|
|
// load the names of the columns we want to collect the values for |
|
122
|
|
|
$columnNames = $this->getLoader()->load($this->getSubject()->getConfiguration()); |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
// collect the values |
|
125
|
|
|
foreach ($columnNames as $columnName) { |
|
126
|
|
|
$values[$columnName] = array(Uuid::uuid4()->toString() => $this->getValue($columnName)); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
// merge the collected values into the registry |
|
130
|
|
|
$this->mergeStatus(array(RegistryKeys::COLLECTED_COLUMNS => $values)); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.