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
PostCode.php
Go to the documentation of this file.
1
<?php
25
#require_once 'Zend/Validate/Abstract.php';
26
30
#require_once 'Zend/Locale/Format.php';
31
38
class
Zend_Validate_PostCode
extends
Zend_Validate_Abstract
39
{
40
const
INVALID
=
'postcodeInvalid'
;
41
const
NO_MATCH
=
'postcodeNoMatch'
;
42
46
protected
$_messageTemplates
= array(
47
self::INVALID =>
"Invalid type given. String or integer expected"
,
48
self::NO_MATCH =>
"'%value%' does not appear to be a postal code"
,
49
);
50
56
protected
$_locale
;
57
63
protected
$_format
;
64
74
public
function
__construct
(
$options
=
null
)
75
{
76
if
(
$options
instanceof
Zend_Config
) {
77
$options
=
$options
->toArray();
78
}
79
80
if
(empty(
$options
)) {
81
#require_once 'Zend/Registry.php';
82
if
(
Zend_Registry::isRegistered
(
'Zend_Locale'
)) {
83
$this->
setLocale
(
Zend_Registry::get
(
'Zend_Locale'
));
84
}
85
}
elseif
(is_array(
$options
)) {
86
// Received
87
if
(array_key_exists(
'locale'
,
$options
)) {
88
$this->
setLocale
(
$options
[
'locale'
]);
89
}
90
91
if
(array_key_exists(
'format'
,
$options
)) {
92
$this->
setFormat
(
$options
[
'format'
]);
93
}
94
}
elseif
(
$options
instanceof
Zend_Locale
|| is_string(
$options
)) {
95
// Received Locale object or string locale
96
$this->
setLocale
(
$options
);
97
}
98
99
$format
= $this->
getFormat
();
100
if
(empty(
$format
)) {
101
#require_once 'Zend/Validate/Exception.php';
102
throw
new
Zend_Validate_Exception
(
"A postcode-format string has to be given for validation"
);
103
}
104
}
105
111
public
function
getLocale
()
112
{
113
return
$this->_locale
;
114
}
115
124
public
function
setLocale
($locale =
null
)
125
{
126
#require_once 'Zend/Locale.php';
127
$this->_locale =
Zend_Locale::findLocale
($locale);
128
$locale =
new
Zend_Locale
($this->_locale);
129
$region = $locale->getRegion();
130
if
(empty($region)) {
131
#require_once 'Zend/Validate/Exception.php';
132
throw
new
Zend_Validate_Exception
(
"Unable to detect a region for the locale '$locale'"
);
133
}
134
135
$format
=
Zend_Locale::getTranslation
(
136
$locale->getRegion(),
137
'postaltoterritory'
,
138
$this->_locale
139
);
140
141
if
(empty(
$format
)) {
142
#require_once 'Zend/Validate/Exception.php';
143
throw
new
Zend_Validate_Exception
(
"Unable to detect a postcode format for the region '{$locale->getRegion()}'"
);
144
}
145
146
$this->
setFormat
(
$format
);
147
return
$this;
148
}
149
155
public
function
getFormat
()
156
{
157
return
$this->_format
;
158
}
159
167
public
function
setFormat
(
$format
)
168
{
169
if
(empty(
$format
) || !is_string(
$format
)) {
170
#require_once 'Zend/Validate/Exception.php';
171
throw
new
Zend_Validate_Exception
(
"A postcode-format string has to be given for validation"
);
172
}
173
174
if
(
$format
[0] !==
'/'
) {
175
$format
=
'/^'
.
$format
;
176
}
177
178
if
(
$format
[strlen(
$format
) - 1] !==
'/'
) {
179
$format
.=
'$/'
;
180
}
181
182
$this->_format =
$format
;
183
return
$this;
184
}
185
194
public
function
isValid
(
$value
)
195
{
196
$this->
_setValue
(
$value
);
197
if
(!is_string(
$value
) && !is_int(
$value
)) {
198
$this->
_error
(self::INVALID);
199
return
false
;
200
}
201
202
$format
= $this->
getFormat
();
203
if
(!preg_match(
$format
,
$value
)) {
204
$this->
_error
(self::NO_MATCH);
205
return
false
;
206
}
207
208
return
true
;
209
}
210
}
Zend_Locale\getTranslation
static getTranslation($value=null, $path=null, $locale=null)
Definition:
Locale.php:1536
Zend_Locale
elseif
elseif(isset( $params[ 'redirect_parent']))
Definition:
iframe.phtml:17
Zend_Validate_PostCode\__construct
__construct($options=null)
Definition:
PostCode.php:74
Zend_Validate_PostCode\NO_MATCH
const NO_MATCH
Definition:
PostCode.php:41
Zend_Validate_PostCode\$_messageTemplates
$_messageTemplates
Definition:
PostCode.php:46
Zend_Validate_PostCode
Definition:
PostCode.php:38
Zend_Validate_Abstract\_error
_error($messageKey, $value=null)
Definition:
Abstract.php:284
Zend_Validate_PostCode\isValid
isValid($value)
Definition:
PostCode.php:194
Zend_Registry\isRegistered
static isRegistered($index)
Definition:
Registry.php:178
Zend_Validate_PostCode\$_locale
$_locale
Definition:
PostCode.php:56
$value
$value
Definition:
gender.phtml:16
$format
$format
Definition:
list.phtml:12
Zend_Validate_Abstract
Definition:
Abstract.php:33
Zend_Validate_PostCode\$_format
$_format
Definition:
PostCode.php:63
Zend_Validate_Abstract\_setValue
_setValue($value)
Definition:
Abstract.php:303
Zend_Validate_PostCode\setFormat
setFormat($format)
Definition:
PostCode.php:167
Zend_Locale\findLocale
static findLocale($locale=null)
Definition:
Locale.php:1740
Zend_Validate_PostCode\getLocale
getLocale()
Definition:
PostCode.php:111
Zend_Config
Zend_Validate_PostCode\INVALID
const INVALID
Definition:
PostCode.php:40
Zend_Validate_PostCode\setLocale
setLocale($locale=null)
Definition:
PostCode.php:124
Zend_Validate_Exception
Definition:
Exception.php:33
Zend_Validate_PostCode\getFormat
getFormat()
Definition:
PostCode.php:155
$options
$options
Definition:
multiple_mixed_products.php:29
Zend_Registry\get
static get($index)
Definition:
Registry.php:141