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

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 = 'floatInvalid'
 
const NOT_FLOAT = 'notFloat'
 

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 Float.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $locale = null)

Constructor for the float validator

Parameters
string | Zend_Config | Zend_Locale$locale

Definition at line 58 of file Float.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  $this->setLocale($locale);
80  }
setLocale($locale=null)
Definition: Float.php:96
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 85 of file Float.php.

86  {
87  return $this->_locale;
88  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value is a floating-point value

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 111 of file Float.php.

112  {
113  if (!is_string($value) && !is_int($value) && !is_float($value)) {
114  $this->_error(self::INVALID);
115  return false;
116  }
117 
118  if (is_float($value)) {
119  return true;
120  }
121 
122  $this->_setValue($value);
123  try {
124  if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
125  $this->_error(self::NOT_FLOAT);
126  return false;
127  }
128  } catch (Zend_Locale_Exception $e) {
129  $this->_error(self::NOT_FLOAT);
130  return false;
131  }
132 
133  return true;
134  }
static isFloat($value, array $options=array())
Definition: Format.php:673
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16

◆ setLocale()

setLocale (   $locale = null)

Sets the locale to use

Parameters
string | Zend_Locale$locale
Returns
$this

Definition at line 96 of file Float.php.

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

Field Documentation

◆ $_locale

$_locale
protected

Definition at line 51 of file Float.php.

◆ $_messageTemplates

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

Definition at line 46 of file Float.php.

◆ INVALID

const INVALID = 'floatInvalid'

Definition at line 40 of file Float.php.

◆ NOT_FLOAT

const NOT_FLOAT = 'notFloat'

Definition at line 41 of file Float.php.


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