5
5
*/
6
6
namespace Magento \Backend \Model \Menu \Item ;
7
7
8
+ use BadMethodCallException ;
9
+ use InvalidArgumentException ;
10
+ use Zend_Validate ;
11
+
8
12
/**
13
+ * Class Validator
14
+ *
15
+ * @package Magento\Backend\Model\Menu\Item
9
16
* @api
10
17
* @since 100.0.2
11
18
*/
@@ -28,7 +35,7 @@ class Validator
28
35
/**
29
36
* The list of primitive validators
30
37
*
31
- * @var \ Zend_Validate[]
38
+ * @var Zend_Validate[]
32
39
*/
33
40
protected $ _validators = [];
34
41
@@ -37,17 +44,17 @@ class Validator
37
44
*/
38
45
public function __construct ()
39
46
{
40
- $ idValidator = new \ Zend_Validate ();
47
+ $ idValidator = new Zend_Validate ();
41
48
$ idValidator ->addValidator (new \Zend_Validate_StringLength (['min ' => 3 ]));
42
49
$ idValidator ->addValidator (new \Zend_Validate_Regex ('/^[A-Za-z0-9\/:_]+$/ ' ));
43
50
44
- $ resourceValidator = new \ Zend_Validate ();
51
+ $ resourceValidator = new Zend_Validate ();
45
52
$ resourceValidator ->addValidator (new \Zend_Validate_StringLength (['min ' => 8 ]));
46
53
$ resourceValidator ->addValidator (
47
54
new \Zend_Validate_Regex ('/^[A-Z][A-Za-z0-9]+_[A-Z][A-Za-z0-9]+::[A-Za-z_0-9]+$/ ' )
48
55
);
49
56
50
- $ attributeValidator = new \ Zend_Validate ();
57
+ $ attributeValidator = new Zend_Validate ();
51
58
$ attributeValidator ->addValidator (new \Zend_Validate_StringLength (['min ' => 3 ]));
52
59
$ attributeValidator ->addValidator (new \Zend_Validate_Regex ('/^[A-Za-z0-9\/_\-]+$/ ' ));
53
60
@@ -70,8 +77,8 @@ public function __construct()
70
77
*
71
78
* @param array $data
72
79
* @return void
73
- * @throws \ InvalidArgumentException
74
- * @throws \ BadMethodCallException
80
+ * @throws InvalidArgumentException
81
+ * @throws BadMethodCallException
75
82
*/
76
83
public function validate ($ data )
77
84
{
@@ -101,15 +108,16 @@ private function checkMenuItemIsRemoved($data)
101
108
102
109
/**
103
110
* Check that menu item contains all required data
111
+ *
104
112
* @param array $data
105
113
*
106
- * @throws \ BadMethodCallException
114
+ * @throws BadMethodCallException
107
115
*/
108
116
private function assertContainsRequiredParameters ($ data )
109
117
{
110
118
foreach ($ this ->_required as $ param ) {
111
119
if (!isset ($ data [$ param ])) {
112
- throw new \ BadMethodCallException ('Missing required param ' . $ param );
120
+ throw new BadMethodCallException ('Missing required param ' . $ param );
113
121
}
114
122
}
115
123
}
@@ -118,12 +126,12 @@ private function assertContainsRequiredParameters($data)
118
126
* Check that menu item id is not used
119
127
*
120
128
* @param string $id
121
- * @throws \ InvalidArgumentException
129
+ * @throws InvalidArgumentException
122
130
*/
123
131
private function assertIdentifierIsNotUsed ($ id )
124
132
{
125
133
if (array_search ($ id , $ this ->_ids ) !== false ) {
126
- throw new \ InvalidArgumentException ('Item with id ' . $ id . ' already exists ' );
134
+ throw new InvalidArgumentException ('Item with id ' . $ id . ' already exists ' );
127
135
}
128
136
}
129
137
@@ -132,7 +140,7 @@ private function assertIdentifierIsNotUsed($id)
132
140
*
133
141
* @param string $param
134
142
* @param mixed $value
135
- * @throws \ InvalidArgumentException
143
+ * @throws InvalidArgumentException
136
144
*/
137
145
private function validateMenuItemParameter ($ param , $ value )
138
146
{
@@ -148,7 +156,7 @@ private function validateMenuItemParameter($param, $value)
148
156
return ;
149
157
}
150
158
151
- throw new \ InvalidArgumentException (
159
+ throw new InvalidArgumentException (
152
160
"Param " . $ param . " doesn't pass validation: " . implode (
153
161
'; ' ,
154
162
$ validator ->getMessages ()
@@ -162,16 +170,16 @@ private function validateMenuItemParameter($param, $value)
162
170
* @param string $param
163
171
* @param mixed $value
164
172
* @return void
165
- * @throws \ InvalidArgumentException
173
+ * @throws InvalidArgumentException
166
174
*/
167
175
public function validateParam ($ param , $ value )
168
176
{
169
177
if (in_array ($ param , $ this ->_required ) && $ value === null ) {
170
- throw new \ InvalidArgumentException ('Param ' . $ param . ' is required ' );
178
+ throw new InvalidArgumentException ('Param ' . $ param . ' is required ' );
171
179
}
172
180
173
181
if ($ value !== null && isset ($ this ->_validators [$ param ]) && !$ this ->_validators [$ param ]->isValid ($ value )) {
174
- throw new \ InvalidArgumentException (
182
+ throw new InvalidArgumentException (
175
183
'Param ' . $ param . ' doesn \'t pass validation: ' . implode (
176
184
'; ' ,
177
185
$ this ->_validators [$ param ]->getMessages ()
0 commit comments