6
6
* PHP version 7
7
7
*
8
8
* @author MET <met@techdivision.com>
9
- * @copyright 20212 TechDivision GmbH <info@techdivision.com>
9
+ * @copyright 2022 TechDivision GmbH <info@techdivision.com>
10
10
* @license https://opensource.org/licenses/MIT
11
11
* @link https://github.com/techdivision/import-attribute
12
12
* @link http://www.techdivision.com
15
15
namespace TechDivision \Import \Attribute \Callbacks ;
16
16
17
17
use TechDivision \Import \Attribute \Utils \ColumnKeys ;
18
- use TechDivision \Import \Callbacks \IndexedArrayValidatorCallback ;
19
- use TechDivision \Import \Loaders \LoaderInterface ;
20
- use TechDivision \Import \Subjects \SubjectInterface ;
21
- use TechDivision \Import \Utils \RegistryKeys ;
22
18
23
19
/**
24
20
* A callback implementation that validates the a list of attribute set names.
25
21
*
26
- * @author Martin Eisenführer <m.eisenfuehrer @techdivision.com>
27
- * @copyright 2021 TechDivision GmbH <info@techdivision.com>
22
+ * @author MET <met @techdivision.com>
23
+ * @copyright 2022 TechDivision GmbH <info@techdivision.com>
28
24
* @license https://opensource.org/licenses/MIT
29
25
* @link https://github.com/techdivision/import-attribute
30
26
* @link http://www.techdivision.com
31
27
*/
32
- class AttributeRelationFrontendInputTypeToBackendTypeValidatorCallback extends IndexedArrayValidatorCallback
28
+ class AttributeRelationFrontendInputTypeToBackendTypeValidatorCallback extends AbstractAttributeValidatorCallback
33
29
{
34
-
35
- /**
36
- * The array with the values of the main row.
37
- *
38
- * @var array
39
- */
40
- private $ mainRowValues = array ();
41
-
42
- /**
43
- * The main row value loader instance to load the validations with.
44
- *
45
- * @var \TechDivision\Import\Loaders\LoaderInterface
46
- */
47
- private $ mainRowValueLoader ;
48
-
49
- /**
50
- * Initializes the callback with the loader instance.
51
- *
52
- * @param \TechDivision\Import\Loaders\LoaderInterface $loader The loader instance to load the validations with
53
- * @param \TechDivision\Import\Loaders\LoaderInterface $mainRowValueLoader The loader instance to load the main row values for of the attribute
54
- * @param boolean $nullable The flag to decide whether or not the value can be empty
55
- * @param boolean $mainRowOnly The flag to decide whether or not the value has to be validated on the main row only
56
- */
57
- public function __construct (LoaderInterface $ loader , LoaderInterface $ mainRowValueLoader , $ nullable = false , $ mainRowOnly = false )
58
- {
59
-
60
- // pass the loader to the parent instance
61
- parent ::__construct ($ loader );
62
-
63
- // the loader for the main row values
64
- $ this ->mainRowValueLoader = $ mainRowValueLoader ;
65
-
66
- // initialize the flags with the passed values
67
- $ this ->nullable = $ nullable ;
68
- $ this ->mainRowOnly = $ mainRowOnly ;
69
- }
70
-
71
- /**
72
- * Will be invoked by the callback visitor when a factory has been defined to create the callback instance.
73
- *
74
- * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance
75
- *
76
- * @return \TechDivision\Import\Callbacks\CallbackInterface The callback instance
77
- */
78
- public function createCallback (SubjectInterface $ subject )
79
- {
80
-
81
- // load the main row values as fallback for a store view row
82
- $ this ->mainRowValues = $ this ->mainRowValueLoader ->load ();
83
-
84
- // return the initialized instance
85
- return parent ::createCallback ($ subject );
86
- }
87
-
88
30
/**
89
31
* Will be invoked by the observer it has been registered for.
90
32
*
@@ -96,7 +38,6 @@ public function createCallback(SubjectInterface $subject)
96
38
*/
97
39
public function handle ($ attributeCode = null , $ attributeValue = null )
98
40
{
99
-
100
41
// query whether or not the passed value
101
42
// IS empty and empty values are allowed
102
43
if ($ this ->isNullable ($ attributeValue )) {
@@ -118,62 +59,25 @@ public function handle($attributeCode = null, $attributeValue = null)
118
59
return ;
119
60
}
120
61
$ message = sprintf (
121
- 'Found invalid backend input type "%s" for attribute with code "%s" for frontend Type "%s", must be one of "%s" as backend type ' ,
62
+ 'Found invalid backend_type "%s" for attribute "%s" with frontend Type "%s", must be one of "%s" as backend_type ' ,
122
63
$ backendType ,
123
64
$ this ->getSubject ()->getValue (ColumnKeys::ATTRIBUTE_CODE ),
124
- $ this -> getValue (ColumnKeys:: FRONTEND_INPUT ) ,
65
+ $ attributeCode ,
125
66
implode (', ' , $ backendTypeValidation [ColumnKeys::BACKEND_TYPE ])
126
67
);
127
- if ($ this ->getSubject ()->isStrictMode ()) {
128
- // throw an exception if the value is NOT in the array
129
- throw new \InvalidArgumentException ($ message );
130
- }
131
- $ this ->getSubject ()->getSystemLogger ()->warning ($ message );
132
- $ this ->getSubject ()->mergeStatus (
133
- array (
134
- RegistryKeys::NO_STRICT_VALIDATIONS => array (
135
- basename ($ this ->getSubject ()->getFilename ()) => array (
136
- $ this ->getSubject ()->getLineNumber () => array (
137
- ColumnKeys::BACKEND_TYPE => $ message
138
- )
139
- )
140
- )
141
- )
142
- );
143
- return ;
68
+
69
+ // throw an exception if the value is NOT in the array
70
+ throw new \InvalidArgumentException ($ message );
144
71
}
145
- } else {
146
- continue ;
147
72
}
148
- // throw an exception if the necessary configuration is NOT available
149
- throw new \InvalidArgumentException (
150
- sprintf (
151
- 'Missing custom validation configuration "frontend_input" type within configuration for column "%s" ' ,
152
- $ this ->getSubject ()->getValue (ColumnKeys::ATTRIBUTE_CODE )
153
- )
154
- );
155
73
}
156
- }
157
-
158
- /**
159
- * Resolve's the value with the passed colum name from the actual row. If the
160
- * column does not contain a value, the value from the main row, if available
161
- * will be returned.
162
- *
163
- * @param string $name The name of the column to return the value for
164
- *
165
- * @return mixed|null The value
166
- */
167
- public function getValue ($ name )
168
- {
169
-
170
- // load the attribute code of the actual EAV attribute
171
- $ attributeCode = $ this ->getSubject ()->getValue (ColumnKeys::ATTRIBUTE_CODE );
172
-
173
- // load the value of the main row as fallback, if available
174
- $ mainRowValue = isset ($ this ->mainRowValues [$ attributeCode ]) ? $ this ->mainRowValues [$ attributeCode ] : null ;
175
74
176
- // return the value of the passed colmn name
177
- return $ this ->getSubject ()->getValue ($ name , $ mainRowValue );
75
+ // throw an exception if the necessary configuration is NOT available
76
+ throw new \InvalidArgumentException (
77
+ sprintf (
78
+ 'Missing custom validation configuration "backend_type" type within configuration for column "%s" ' ,
79
+ $ this ->getSubject ()->getValue (ColumnKeys::ATTRIBUTE_CODE )
80
+ )
81
+ );
178
82
}
179
83
}
0 commit comments