|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Attribute\Set\Callbacks\AttributeSetNameValidatorCallback |
|
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\Callbacks; |
|
16
|
|
|
|
|
17
|
|
|
use TechDivision\Import\Attribute\Set\Utils\ColumnKeys; |
|
18
|
|
|
use TechDivision\Import\Callbacks\IndexedArrayValidatorCallback; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* A callback implementation that validates the attribute group names in an attribute import. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Tim Wagner <[email protected]> |
|
24
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
25
|
|
|
* @license https://opensource.org/licenses/MIT |
|
26
|
|
|
* @link https://github.com/techdivision/import-attribute-set |
|
27
|
|
|
* @link http://www.techdivision.com |
|
28
|
|
|
*/ |
|
29
|
|
|
class AttributeSetNameValidatorCallback extends IndexedArrayValidatorCallback |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Will be invoked by the observer it has been registered for. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string|null $attributeCode The code of the attribute that has to be validated |
|
36
|
|
|
* @param string|null $attributeValue The attribute value to be validated |
|
37
|
|
|
* |
|
38
|
|
|
* @return mixed The modified value |
|
39
|
|
|
*/ |
|
40
|
|
|
public function handle($attributeCode = null, $attributeValue = null) |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
// load the subject instance |
|
44
|
|
|
$subject = $this->getSubject(); |
|
45
|
|
|
|
|
46
|
|
|
// query whether or not the attribute value is emtpy |
|
47
|
|
|
if ($this->isNullable($attributeValue)) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// load the validations for the attribute set with the given name |
|
52
|
|
|
$validations = $this->getValidations($subject->getValue(ColumnKeys::ENTITY_TYPE_CODE)); |
|
53
|
|
|
|
|
54
|
|
|
// query whether or not the value is valid |
|
55
|
|
|
if (in_array($attributeValue, $validations)) { |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// throw an exception if the value is NOT in the array |
|
60
|
|
|
throw new \InvalidArgumentException( |
|
61
|
|
|
sprintf('Found invalid attribute set name "%s"', $attributeValue) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|