1 | <?php |
||
35 | trait ExportableTrait |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * The array containing the data for product type configuration (configurables, bundles, etc). |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $artefacs = array(); |
||
44 | |||
45 | /** |
||
46 | * The export adapter instance. |
||
47 | * |
||
48 | * @var \TechDivision\Import\Adapter\ExportAdapterInterface |
||
49 | */ |
||
50 | protected $exportAdapter; |
||
51 | |||
52 | /** |
||
53 | * The ID of the product that has been created recently. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $lastEntityId; |
||
58 | |||
59 | /** |
||
60 | * Return's the artefacts for post-processing. |
||
61 | * |
||
62 | * @return array The artefacts |
||
63 | */ |
||
64 | 3 | public function getArtefacts() |
|
68 | |||
69 | /** |
||
70 | * Add the passed product type artefacts to the product with the |
||
71 | * last entity ID. |
||
72 | * |
||
73 | * @param string $type The artefact type, e. g. configurable |
||
74 | * @param array $artefacts The product type artefacts |
||
75 | * @param boolean $override Whether or not the artefacts for the actual entity ID has to be overwritten |
||
76 | * |
||
77 | * @return void |
||
78 | * @uses \TechDivision\Import\Product\Subjects\BunchSubject::getLastEntityId() |
||
79 | */ |
||
80 | 4 | public function addArtefacts($type, array $artefacts, $override = true) |
|
81 | { |
||
82 | |||
83 | // query whether or not, any artefacts are available |
||
84 | 4 | if (sizeof($artefacts) === 0) { |
|
85 | 1 | return; |
|
86 | } |
||
87 | |||
88 | // serialize the original data |
||
89 | 3 | array_walk($artefacts, function (&$artefact) { |
|
90 | 3 | if (isset($artefact[ColumnKeys::ORIGINAL_DATA])) { |
|
91 | 1 | $artefact[ColumnKeys::ORIGINAL_DATA] = serialize($artefact[ColumnKeys::ORIGINAL_DATA]); |
|
92 | } |
||
93 | 3 | }); |
|
94 | |||
95 | // query whether or not, existing artefacts has to be overwritten |
||
96 | 3 | if ($override === true) { |
|
97 | 3 | $this->overrideArtefacts($type, $artefacts); |
|
98 | } else { |
||
99 | $this->appendArtefacts($type, $artefacts); |
||
100 | } |
||
101 | 3 | } |
|
102 | |||
103 | /** |
||
104 | * Add the passed product type artefacts to the product with the |
||
105 | * last entity ID and overrides existing ones with the same key. |
||
106 | * |
||
107 | * @param string $type The artefact type, e. g. configurable |
||
108 | * @param array $artefacts The product type artefacts |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | 3 | protected function overrideArtefacts($type, array $artefacts) |
|
118 | |||
119 | /** |
||
120 | * Append's the passed product type artefacts to the product with the |
||
121 | * last entity ID. |
||
122 | * |
||
123 | * @param string $type The artefact type, e. g. configurable |
||
124 | * @param array $artefacts The product type artefacts |
||
125 | * |
||
126 | * @return void |
||
127 | */ |
||
128 | protected function appendArtefacts($type, array $artefacts) |
||
134 | |||
135 | /** |
||
136 | * Return the artefacts for the passed type and entity ID. |
||
137 | * |
||
138 | * @param string $type The artefact type, e. g. configurable |
||
139 | * @param string $entityId The entity ID to return the artefacts for |
||
140 | * |
||
141 | * @return array The array with the artefacts |
||
142 | * @throws \Exception Is thrown, if no artefacts are available |
||
143 | */ |
||
144 | 2 | public function getArtefactsByTypeAndEntityId($type, $entityId) |
|
172 | |||
173 | /** |
||
174 | * Queries whether or not artefacts for the passed type and entity ID are available. |
||
175 | * |
||
176 | * @param string $type The artefact type, e. g. configurable |
||
177 | * @param string $entityId The entity ID to return the artefacts for |
||
178 | * |
||
179 | * @return boolean TRUE if artefacts are available, else FALSE |
||
180 | */ |
||
181 | public function hasArtefactsByTypeAndEntityId($type, $entityId) |
||
185 | |||
186 | /** |
||
187 | * Create's and return's a new empty artefact entity. |
||
188 | * |
||
189 | * @param array $columns The array with the column data |
||
190 | * @param array $originalColumnNames The array with a mapping from the old to the new column names |
||
191 | * |
||
192 | * @return array The new artefact entity |
||
193 | */ |
||
194 | 1 | public function newArtefact(array $columns, array $originalColumnNames = array()) |
|
215 | |||
216 | /** |
||
217 | * Export's the artefacts to CSV files. |
||
218 | * |
||
219 | * @param integer $timestamp The timestamp part of the original import file |
||
220 | * @param string $counter The counter part of the origin import file |
||
221 | * |
||
222 | * @return void |
||
223 | */ |
||
224 | 1 | public function export($timestamp, $counter) |
|
228 | |||
229 | /** |
||
230 | * Set's the exporter adapter instance. |
||
231 | * |
||
232 | * @param \TechDivision\Import\Adapter\ExportAdapterInterface $exportAdapter The exporter adapter instance |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | 2 | public function setExportAdapter(ExportAdapterInterface $exportAdapter) |
|
240 | |||
241 | /** |
||
242 | * Return's the exporter adapter instance. |
||
243 | * |
||
244 | * @return \TechDivision\Import\Adapter\ExportAdapterInterface The exporter adapter instance |
||
245 | */ |
||
246 | 2 | public function getExportAdapter() |
|
250 | |||
251 | /** |
||
252 | * Set's the ID of the product that has been created recently. |
||
253 | * |
||
254 | * @param string $lastEntityId The entity ID |
||
255 | * |
||
256 | * @return void |
||
257 | */ |
||
258 | 3 | public function setLastEntityId($lastEntityId) |
|
262 | |||
263 | /** |
||
264 | * Return's the ID of the product that has been created recently. |
||
265 | * |
||
266 | * @return string The entity Id |
||
267 | */ |
||
268 | 3 | public function getLastEntityId() |
|
272 | } |
||
273 |
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.