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

Public Member Functions

 __construct ($locale=null)
 
 getLocale ()
 
 setLocale ($locale=null)
 
 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 = 'intInvalid'
 
const NOT_INT = 'notInt'
 

Protected Attributes

 $_messageTemplates
 
 $_locale
 
- 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 Int.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $locale = null)

Constructor for the integer validator

Parameters
string | Zend_Config | Zend_Locale$locale

Definition at line 58 of file Int.php.

59  {
60  if ($locale instanceof Zend_Config) {
61  $locale = $locale->toArray();
62  }
63 
64  if (is_array($locale)) {
65  if (array_key_exists('locale', $locale)) {
66  $locale = $locale['locale'];
67  } else {
68  $locale = null;
69  }
70  }
71 
72  if (empty($locale)) {
73  #require_once 'Zend/Registry.php';
74  if (Zend_Registry::isRegistered('Zend_Locale')) {
75  $locale = Zend_Registry::get('Zend_Locale');
76  }
77  }
78 
79  if ($locale !== null) {
80  $this->setLocale($locale);
81  }
82  }
setLocale($locale=null)
Definition: Int.php:98
static isRegistered($index)
Definition: Registry.php:178
static get($index)
Definition: Registry.php:141

Member Function Documentation

◆ getLocale()

getLocale ( )

Returns the set locale

Definition at line 87 of file Int.php.

88  {
89  return $this->_locale;
90  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

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

Parameters
string | integer$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 113 of file Int.php.

114  {
115  if (!is_string($value) && !is_int($value) && !is_float($value)) {
116  $this->_error(self::INVALID);
117  return false;
118  }
119 
120  if (is_int($value)) {
121  return true;
122  }
123 
124  $this->_setValue($value);
125  if ($this->_locale === null) {
126  $locale = localeconv();
127  $valueFiltered = str_replace($locale['decimal_point'], '.', $value);
128  $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
129 
130  if (strval(intval($valueFiltered)) != $valueFiltered) {
131  $this->_error(self::NOT_INT);
132  return false;
133  }
134 
135  } else {
136  try {
137  if (!Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) {
138  $this->_error(self::NOT_INT);
139  return false;
140  }
141  } catch (Zend_Locale_Exception $e) {
142  $this->_error(self::NOT_INT);
143  return false;
144  }
145  }
146 
147  return true;
148  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
static isInteger($value, array $options=array())
Definition: Format.php:721

◆ setLocale()

setLocale (   $locale = null)

Sets the locale to use

Parameters
string | Zend_Locale$locale
Returns
$this

Definition at line 98 of file Int.php.

99  {
100  #require_once 'Zend/Locale.php';
101  $this->_locale = Zend_Locale::findLocale($locale);
102  return $this;
103  }
static findLocale($locale=null)
Definition: Locale.php:1740

Field Documentation

◆ $_locale

$_locale
protected

Definition at line 51 of file Int.php.

◆ $_messageTemplates

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

Definition at line 46 of file Int.php.

◆ INVALID

const INVALID = 'intInvalid'

Definition at line 40 of file Int.php.

◆ NOT_INT

const NOT_INT = 'notInt'

Definition at line 41 of file Int.php.


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