Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Validate_PostCode Class Reference
Inheritance diagram for Zend_Validate_PostCode:
Zend_Validate_Abstract Zend_Validate_Interface

Public Member Functions

 __construct ($options=null)
 
 getLocale ()
 
 setLocale ($locale=null)
 
 getFormat ()
 
 setFormat ($format)
 
 isValid ($value)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 

Data Fields

const INVALID = 'postcodeInvalid'
 
const NO_MATCH = 'postcodeNoMatch'
 

Protected Attributes

 $_messageTemplates
 
 $_locale
 
 $_format
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 38 of file PostCode.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor for the integer validator

Accepts either a string locale, a Zend_Locale object, or an array or Zend_Config object containing the keys "locale" and/or "format".

Parameters
string | Zend_Locale | array | Zend_Config$options
Exceptions
Zend_Validate_ExceptionOn empty format

Definition at line 74 of file PostCode.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static isRegistered($index)
Definition: Registry.php:178
$format
Definition: list.phtml:12
setFormat($format)
Definition: PostCode.php:167
setLocale($locale=null)
Definition: PostCode.php:124
getFormat()
Definition: PostCode.php:155
static get($index)
Definition: Registry.php:141

Member Function Documentation

◆ getFormat()

getFormat ( )

Returns the set postal code format

Returns
string

Definition at line 155 of file PostCode.php.

156  {
157  return $this->_format;
158  }
$_format
Definition: PostCode.php:63

◆ getLocale()

getLocale ( )

Returns the set locale

Returns
string|Zend_Locale The set locale

Definition at line 111 of file PostCode.php.

112  {
113  return $this->_locale;
114  }
$_locale
Definition: PostCode.php:56

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value is a valid postalcode

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 194 of file PostCode.php.

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  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
$format
Definition: list.phtml:12
getFormat()
Definition: PostCode.php:155

◆ setFormat()

setFormat (   $format)

Sets a self defined postal format as regex

Parameters
string$format
Exceptions
Zend_Validate_ExceptionOn empty format
Returns
Zend_Validate_PostCode Provides a fluent interface

Definition at line 167 of file PostCode.php.

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  }
$format
Definition: list.phtml:12

◆ setLocale()

setLocale (   $locale = null)

Sets the locale to use

Parameters
string | Zend_Locale$locale
Exceptions
Zend_Validate_ExceptionOn unrecognised region
Zend_Validate_ExceptionOn not detected format
Returns
Zend_Validate_PostCode Provides a fluent interface

Definition at line 124 of file PostCode.php.

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 
136  $locale->getRegion(),
137  'postaltoterritory',
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  }
static getTranslation($value=null, $path=null, $locale=null)
Definition: Locale.php:1536
$_locale
Definition: PostCode.php:56
$format
Definition: list.phtml:12
setFormat($format)
Definition: PostCode.php:167
static findLocale($locale=null)
Definition: Locale.php:1740

Field Documentation

◆ $_format

$_format
protected

Definition at line 63 of file PostCode.php.

◆ $_locale

$_locale
protected

Definition at line 56 of file PostCode.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INVALID => "Invalid type given. String or integer expected",
self::NO_MATCH => "'%value%' does not appear to be a postal code",
)

Definition at line 46 of file PostCode.php.

◆ INVALID

const INVALID = 'postcodeInvalid'

Definition at line 40 of file PostCode.php.

◆ NO_MATCH

const NO_MATCH = 'postcodeNoMatch'

Definition at line 41 of file PostCode.php.


The documentation for this class was generated from the following file: