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