Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
zendframework1
library
Zend
Validate
Ip.php
Go to the documentation of this file.
1
<?php
25
#require_once 'Zend/Validate/Abstract.php';
26
33
class
Zend_Validate_Ip
extends
Zend_Validate_Abstract
34
{
35
const
INVALID
=
'ipInvalid'
;
36
const
NOT_IP_ADDRESS
=
'notIpAddress'
;
37
41
protected
$_messageTemplates
= array(
42
self::INVALID =>
"Invalid type given. String expected"
,
43
self::NOT_IP_ADDRESS =>
"'%value%' does not appear to be a valid IP address"
,
44
);
45
51
protected
$_options
= array(
52
'allowipv6'
=>
true
,
53
'allowipv4'
=>
true
54
);
55
61
public
function
__construct
(
$options
= array())
62
{
63
if
(
$options
instanceof
Zend_Config
) {
64
$options
=
$options
->toArray();
65
}
else
if
(!is_array(
$options
)) {
66
$options
= func_get_args();
67
$temp[
'allowipv6'
] = array_shift(
$options
);
68
if
(!empty(
$options
)) {
69
$temp[
'allowipv4'
] = array_shift(
$options
);
70
}
71
72
$options
= $temp;
73
}
74
75
$options
+=
$this->_options
;
76
$this->
setOptions
(
$options
);
77
}
78
84
public
function
getOptions
()
85
{
86
return
$this->_options
;
87
}
88
96
public
function
setOptions
(
$options
)
97
{
98
if
(array_key_exists(
'allowipv6'
,
$options
)) {
99
$this->_options[
'allowipv6'
] = (boolean)
$options
[
'allowipv6'
];
100
}
101
102
if
(array_key_exists(
'allowipv4'
,
$options
)) {
103
$this->_options[
'allowipv4'
] = (boolean)
$options
[
'allowipv4'
];
104
}
105
106
if
(!$this->_options[
'allowipv4'
] && !$this->_options[
'allowipv6'
]) {
107
#require_once 'Zend/Validate/Exception.php';
108
throw
new
Zend_Validate_Exception
(
'Nothing to validate. Check your options'
);
109
}
110
111
return
$this;
112
}
113
122
public
function
isValid
(
$value
)
123
{
124
if
(!is_string(
$value
)) {
125
$this->
_error
(self::INVALID);
126
return
false
;
127
}
128
129
$this->
_setValue
(
$value
);
130
if
(($this->_options[
'allowipv4'
] && !$this->_options[
'allowipv6'
] && !$this->
_validateIPv4
(
$value
)) ||
131
(!$this->_options[
'allowipv4'
] && $this->_options[
'allowipv6'
] && !$this->
_validateIPv6
(
$value
)) ||
132
($this->_options[
'allowipv4'
] && $this->_options[
'allowipv6'
] && !$this->
_validateIPv4
(
$value
) && !$this->
_validateIPv6
(
$value
))) {
133
$this->
_error
(self::NOT_IP_ADDRESS);
134
return
false
;
135
}
136
137
return
true
;
138
}
139
146
protected
function
_validateIPv4
(
$value
) {
147
$ip2long = ip2long(
$value
);
148
if
($ip2long ===
false
) {
149
return
false
;
150
}
151
152
return
$value
== long2ip($ip2long);
153
}
154
162
protected
function
_validateIPv6
(
$value
) {
163
if
(strlen(
$value
) < 3) {
164
return
$value
==
'::'
;
165
}
166
167
if
(strpos(
$value
,
'.'
)) {
168
$lastcolon = strrpos(
$value
,
':'
);
169
if
(!($lastcolon && $this->
_validateIPv4
(substr(
$value
, $lastcolon + 1)))) {
170
return
false
;
171
}
172
173
$value
= substr(
$value
, 0, $lastcolon) .
':0:0'
;
174
}
175
176
if
(strpos(
$value
,
'::'
) ===
false
) {
177
return
preg_match(
'/\A(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}\z/i'
,
$value
);
178
}
179
180
$colonCount = substr_count(
$value
,
':'
);
181
if
($colonCount < 8) {
182
return
preg_match(
'/\A(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?\z/i'
,
$value
);
183
}
184
185
// special case with ending or starting double colon
186
if
($colonCount == 8) {
187
return
preg_match(
'/\A(?:::)?(?:[a-f0-9]{1,4}:){6}[a-f0-9]{1,4}(?:::)?\z/i'
,
$value
);
188
}
189
190
return
false
;
191
}
192
}
Zend_Validate_Ip\NOT_IP_ADDRESS
const NOT_IP_ADDRESS
Definition:
Ip.php:36
Zend_Validate_Ip\INVALID
const INVALID
Definition:
Ip.php:35
Zend_Validate_Ip\setOptions
setOptions($options)
Definition:
Ip.php:96
Zend_Validate_Abstract\_error
_error($messageKey, $value=null)
Definition:
Abstract.php:284
Zend_Validate_Ip
Definition:
Ip.php:33
Zend_Validate_Ip\__construct
__construct($options=array())
Definition:
Ip.php:61
$value
$value
Definition:
gender.phtml:16
Zend_Validate_Abstract
Definition:
Abstract.php:33
Zend_Validate_Abstract\_setValue
_setValue($value)
Definition:
Abstract.php:303
Zend_Validate_Ip\_validateIPv6
_validateIPv6($value)
Definition:
Ip.php:162
Zend_Config
Zend_Validate_Ip\_validateIPv4
_validateIPv4($value)
Definition:
Ip.php:146
Zend_Validate_Ip\isValid
isValid($value)
Definition:
Ip.php:122
Zend_Validate_Ip\getOptions
getOptions()
Definition:
Ip.php:84
Zend_Validate_Exception
Definition:
Exception.php:33
Zend_Validate_Ip\$_messageTemplates
$_messageTemplates
Definition:
Ip.php:41
Zend_Validate_Ip\$_options
$_options
Definition:
Ip.php:51
$options
$options
Definition:
multiple_mixed_products.php:29