|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Callbacks\AbstractCallback |
|
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 2016 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\Callbacks; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Observers\ObserverInterface; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* An abstract callback implementation. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/techdivision/import |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
abstract class AbstractCallback implements CallbackInterface |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The observer's subject instance. |
|
39
|
|
|
* |
|
40
|
|
|
* @var \TechDivision\Import\Observers\ObserverInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $observer; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Set's the callback's observer instance. |
|
46
|
|
|
* |
|
47
|
|
|
* @param \TechDivision\Import\Observers\ObserverInterfaceInterface $observer The callback's observer |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function setObserver(ObserverInterface $observer) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->observer = $observer; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Return's the callback's observer instance. |
|
58
|
|
|
* |
|
59
|
|
|
* @return \TechDivision\Import\Observers\ObserverInterfaceInterface The callback's observer |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function getObserver() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->observer; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Return's the observer's subject instance. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \TechDivision\Import\Subjects\SubjectInterface The observer's subject instance |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getSubject() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->getObserver()->getSubject(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Return's the system logger. |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Psr\Log\LoggerInterface The system logger instance |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function getSystemLogger() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->getSubject()->getSystemLogger(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Append's the exception suffix containing filename and line number to the |
|
88
|
|
|
* passed message. If no message has been passed, only the suffix will be |
|
89
|
|
|
* returned. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string|null $message The message to append the exception suffix to |
|
92
|
|
|
* @param string|null $filename The filename used to create the suffix |
|
93
|
|
|
* @param string|null $lineNumber The line number used to create the suffx |
|
94
|
|
|
* |
|
95
|
|
|
* @return string The message with the appended exception suffix |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function appendExceptionSuffix($message = null, $filename = null, $lineNumber = null) |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->getSubject()-> appendExceptionSuffix($message, $filename, $lineNumber); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Wraps the passed exeception into a new one by trying to resolve the original filname, |
|
104
|
|
|
* line number and column name and use it for a detailed exception message. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $columnName The column name that should be resolved |
|
107
|
|
|
* @param \Exception $parent The exception we want to wrap |
|
108
|
|
|
* @param string $className The class name of the exception type we want to wrap the parent one |
|
109
|
|
|
* |
|
110
|
|
|
* @return \Exception the wrapped exception |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function wrapException( |
|
113
|
|
|
$columnName, |
|
114
|
|
|
\Exception $parent = null, |
|
115
|
|
|
$className = '\TechDivision\Import\Exceptions\WrappedColumnException' |
|
116
|
|
|
) { |
|
117
|
|
|
return $this->getSubject()->wrapException($columnName, $parent, $className); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Queries whether or not debug mode is enabled or not, default is TRUE. |
|
122
|
|
|
* |
|
123
|
|
|
* @return boolean TRUE if debug mode is enabled, else FALSE |
|
124
|
|
|
*/ |
|
125
|
|
|
protected function isDebugMode() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->getSubject()->isDebugMode(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Raises the value for the counter with the passed key by one. |
|
132
|
|
|
* |
|
133
|
|
|
* @param mixed $counterName The name of the counter to raise |
|
134
|
|
|
* |
|
135
|
|
|
* @return integer The counter's new value |
|
136
|
|
|
*/ |
|
137
|
|
|
protected function raiseCounter($counterName) |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->getSubject()->raiseCounter($counterName); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Merge the passed array into the status of the actual import. |
|
144
|
|
|
* |
|
145
|
|
|
* @param array $status The status information to be merged |
|
146
|
|
|
* |
|
147
|
|
|
* @return void |
|
148
|
|
|
*/ |
|
149
|
|
|
protected function mergeAttributesRecursive(array $status) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->getSubject()->mergeAttributesRecursive($status); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Resolve's the value with the passed colum name from the actual row. If a callback will |
|
156
|
|
|
* be passed, the callback will be invoked with the found value as parameter. If |
|
157
|
|
|
* the value is NULL or empty, the default value will be returned. |
|
158
|
|
|
* |
|
159
|
|
|
* @param string $name The name of the column to return the value for |
|
160
|
|
|
* @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
|
161
|
|
|
* @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
|
162
|
|
|
* |
|
163
|
|
|
* @return mixed|null The, almost formatted, value |
|
164
|
|
|
*/ |
|
165
|
|
|
protected function getValue($name, $default = null, callable $callback = null) |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->getSubject()->getValue($name, $default, $callback); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Return's the store ID of the store with the passed store view code |
|
172
|
|
|
* |
|
173
|
|
|
* @param string $storeViewCode The store view code to return the store ID for |
|
174
|
|
|
* |
|
175
|
|
|
* @return integer The ID of the store with the passed ID |
|
176
|
|
|
* @throws \Exception Is thrown, if the store with the actual code is not available |
|
177
|
|
|
*/ |
|
178
|
|
|
protected function getStoreId($storeViewCode) |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->getSubject()->getStoreId($storeViewCode); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Return's the store ID of the actual row, or of the default store |
|
185
|
|
|
* if no store view code is set in the CSV file. |
|
186
|
|
|
* |
|
187
|
|
|
* @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
|
188
|
|
|
* |
|
189
|
|
|
* @return integer The ID of the actual store |
|
190
|
|
|
* @throws \Exception Is thrown, if the store with the actual code is not available |
|
191
|
|
|
*/ |
|
192
|
|
|
protected function getRowStoreId($default = null) |
|
193
|
|
|
{ |
|
194
|
|
|
return $this->getSubject()->getRowStoreId($default); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Return's the unique identifier of the actual row, e. g. a products SKU. |
|
199
|
|
|
* |
|
200
|
|
|
* @return mixed The row's unique identifier |
|
201
|
|
|
*/ |
|
202
|
|
|
abstract protected function getUniqueIdentifier(); |
|
203
|
|
|
} |
|
204
|
|
|
|