当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Locale_Format::isNumber方法代码示例

本文整理汇总了PHP中Zend_Locale_Format::isNumber方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::isNumber方法的具体用法?PHP Zend_Locale_Format::isNumber怎么用?PHP Zend_Locale_Format::isNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Locale_Format的用法示例。


在下文中一共展示了Zend_Locale_Format::isNumber方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filter

 /**
  * Defined by Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (Zend_Locale_Format::isNumber($value, $this->_options)) {
         return Zend_Locale_Format::getNumber($value, $this->_options);
         //        if (($this->_options['precision'] === 0) && Zend_Locale_Format::isInteger($value, $this->_options)) {
         // Detect integer
         //            return Zend_Locale_Format::getInteger($value, $this->_options);
         //        } else if (($this->_options['precision'] === null) && Zend_Locale_Format::isFloat($value, $this->_options)) {
         // Detect float
         //            return Zend_Locale_Format::getFloat($value, $this->_options);
         //        } else if (Zend_Locale_Format::isNumber($value, $this->_options)) {
         // Detect all other numbers
         //            return Zend_Locale_Format::getNumber($value, $this->_options);
     } else {
         if ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
             // Special case, no date format specified, detect time input
             return Zend_Locale_Format::getTime($value, $this->_options);
         } else {
             if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) {
                 // Detect date or time input
                 return Zend_Locale_Format::getDate($value, $this->_options);
             }
         }
     }
     return $value;
 }
开发者ID:jingjangjung,项目名称:Storefront,代码行数:34,代码来源:LocalizedToNormalized.php

示例2: validate

 public function validate($validator)
 {
     if (!$this->value && !$validator->fieldIsRequired($this->name)) {
         return true;
     }
     require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php";
     $valid = Zend_Locale_Format::isNumber(trim($this->value), array('locale' => i18n::get_locale()));
     if (!$valid) {
         $validator->validationError($this->name, _t('NumericField.VALIDATION', "'{value}' is not a number, only numbers can be accepted for this field", array('value' => $this->value)), "validation");
         return false;
     }
     return true;
 }
开发者ID:8secs,项目名称:cocina,代码行数:13,代码来源:NumericField.php

示例3: setValue

 /**
  * displays the value in its current locality format
  */
 public function setValue($value, $data = array())
 {
     require_once THIRDPARTY_PATH . "/Zend/Locale/Format.php";
     // If passing in a non-string number, or a value
     // directly from a dataobject then localise this number
     if (is_numeric($value) && !is_string($value) || $value && $data instanceof DataObject) {
         $locale = new Zend_Locale($this->getLocale());
         $this->value = Zend_Locale_Format::toNumber($value, array('locale' => $locale));
     } else {
         if (Zend_Locale_Format::isNumber($this->clean($value), array('locale' => i18n::get_locale()))) {
             // If an invalid number, store it anyway, but validate() will fail
             $this->value = $this->clean($value);
         }
     }
     return $this;
 }
开发者ID:spekulatius,项目名称:silverstripe-bootstrap_extra_fields,代码行数:19,代码来源:BootstrapCurrencyField.php

示例4: isNumeric

 /**
  * Determine if the current value is a valid number in the current locale
  * 
  * @return bool
  */
 protected function isNumeric()
 {
     require_once "Zend/Locale/Format.php";
     $locale = new Zend_Locale($this->getLocale());
     return Zend_Locale_Format::isNumber($this->clean($this->value), array('locale' => $locale));
 }
开发者ID:nicocin,项目名称:silverstripe-framework,代码行数:11,代码来源:NumericField.php

示例5: convert

 /**
  * Get the unit from the form. If it's defined and different than the
  * display unit, convert the value and set it back into this control's value.
  * Then, format with proper number of digits.
  * 
  * Do not call this method more than once!
  */
 protected function convert()
 {
     $user = Transaction::getInstance()->getUser();
     if ($this->getValue() !== null && Zend_Locale_Format::isNumber($this->getValue(), array("locale" => $user->getLocale()))) {
         $form = $this->getForm();
         // Get the 'hidden' value, which indicates the unit of the current value.
         $unit = $form->getValue($this->getUnitFieldName());
         // If the unit is different, convert
         if ($unit && $unit != $this->displayUnit) {
             $measure = MeasureUtils::newMeasure($unit, $this->getValue(), $user->getLocale());
             $unitInfo = MeasureUtils::getUnitInfo($this->displayUnit);
             $measure->setType($unitInfo['constantName']);
             // Sets the new value without rounding and without formatting
             $this->setValue($measure->getValue(-1, $user->getLocale()));
         }
         $format = Formatter::getInstance();
         // Format and round the value
         $this->setValue($format->number($format->getNumber($this->getValue()), $this->decimalDigits));
     }
 }
开发者ID:fruition-sciences,项目名称:phpfw,代码行数:27,代码来源:MeasureTextbox.php

示例6: _beforeSave

 /**
  * Prepare data for save
  *
  * @return Mage_Eav_Model_Entity_Attribute
  * @throws Mage_Eav_Exception
  */
 protected function _beforeSave()
 {
     /**
      * Check for maximum attribute_code length
      */
     if (isset($this->_data['attribute_code']) && !Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) {
         throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
     }
     $defaultValue = $this->getDefaultValue();
     $hasDefaultValue = (string) $defaultValue != '';
     if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
         $locale = Mage::app()->getLocale()->getLocaleCode();
         if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => $locale))) {
             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value'));
         }
         try {
             $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
             $this->setDefaultValue($filter->filter($defaultValue));
         } catch (Exception $e) {
             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value'));
         }
     }
     if ($this->getBackendType() == 'datetime') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('eav/entity_attribute_backend_datetime');
         }
         if (!$this->getFrontendModel()) {
             $this->setFrontendModel('eav/entity_attribute_frontend_datetime');
         }
         // save default date value as timestamp
         if ($hasDefaultValue) {
             $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
             try {
                 $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
                 $this->setDefaultValue($defaultValue);
             } catch (Exception $e) {
                 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default date'));
             }
         }
     }
     if ($this->getBackendType() == 'gallery') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('eav/entity_attribute_backend_media');
         }
     }
     return parent::_beforeSave();
 }
开发者ID:hyhoocchan,项目名称:mage-local,代码行数:53,代码来源:Attribute.php

示例7: testIsNumber

 /**
  * test isNumber
  * expected boolean
  */
 public function testIsNumber()
 {
     $this->assertTrue( Zend_Locale_Format::isNumber('-1.234.567,12345',  array('locale' => 'de_AT')));
     $this->assertFalse(Zend_Locale_Format::isNumber('textwithoutnumber', array('locale' => 'de_AT')));
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:9,代码来源:FormatTest.php

示例8: testShortNotation

 public function testShortNotation()
 {
     $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(0.12345));
     $options = array('locale' => 'de');
     $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(0.12345, Zend_Locale_Format::getNumber(',12345', $options));
     $this->assertEquals('0,75', Zend_Locale_Format::toNumber(0.75, array('locale' => 'de_DE', 'precision' => 2)));
     $this->assertTrue(Zend_Locale_Format::isNumber(',12345', array('locale' => 'de_AT')));
     $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(0.12345));
     $options = array('locale' => 'de');
     $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(0.12345, Zend_Locale_Format::getFloat(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
     $options = array('locale' => 'ar_QA');
     $this->assertEquals('0,12345', Zend_Locale_Format::toFloat(0.12345, $options));
     $this->assertTrue(Zend_Locale_Format::isFloat(',12345', array('locale' => 'de_AT')));
     $this->assertEquals(0, Zend_Locale_Format::getInteger(0.1234567));
     $options = array('locale' => 'de');
     $this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
     $options = array('locale' => 'de_AT');
     $this->assertEquals(0, Zend_Locale_Format::getInteger(',12345', $options));
     $this->assertEquals('0', Zend_Locale_Format::toInteger(0.123, array('locale' => 'de')));
     $options = array('locale' => 'de_AT');
     $this->assertEquals('0', Zend_Locale_Format::toInteger(0.12345, $options));
     $this->assertFalse(Zend_Locale_Format::isInteger(',12345', array('locale' => 'de_AT')));
     $options = array('locale' => 'de_AT');
     $this->assertEquals('0,567', Zend_Locale_Format::toNumber(0.5669999999999999, $options));
 }
开发者ID:ThorstenSuckow,项目名称:conjoon,代码行数:31,代码来源:FormatTest.php

示例9: testIsNumber

 /**
  * test isNumber
  * expected boolean
  */
 public function testIsNumber()
 {
     $this->assertEquals(Zend_Locale_Format::isNumber('-1.234.567,12345', array('locale' => 'de_AT')), true, "true expected");
     $this->assertEquals(Zend_Locale_Format::isNumber('textwithoutnumber', array('locale' => 'de_AT')), false, "false expected");
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:9,代码来源:FormatTest.php

示例10: _beforeSave

 /**
  * Prepare data for save
  *
  * @return Mage_Eav_Model_Entity_Attribute
  */
 protected function _beforeSave()
 {
     // prevent overriding product data
     if (isset($this->_data['attribute_code']) && Mage::getModel('Mage_Catalog_Model_Product')->isReservedAttribute($this)) {
         throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
     }
     /**
      * Check for maximum attribute_code length
      */
     if (isset($this->_data['attribute_code']) && !Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) {
         throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
     }
     $defaultValue = $this->getDefaultValue();
     $hasDefaultValue = (string) $defaultValue != '';
     if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
         if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => Mage::app()->getLocale()->getLocaleCode()))) {
             throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid default decimal value'));
         }
         try {
             $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
             $this->setDefaultValue($filter->filter($defaultValue));
         } catch (Exception $e) {
             throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid default decimal value'));
         }
     }
     if ($this->getBackendType() == 'datetime') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Mage_Eav_Model_Entity_Attribute_Backend_Datetime');
         }
         if (!$this->getFrontendModel()) {
             $this->setFrontendModel('Mage_Eav_Model_Entity_Attribute_Frontend_Datetime');
         }
         // save default date value as timestamp
         if ($hasDefaultValue) {
             $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
             try {
                 $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
                 $this->setDefaultValue($defaultValue);
             } catch (Exception $e) {
                 throw Mage::exception('Mage_Eav', Mage::helper('Mage_Eav_Helper_Data')->__('Invalid default date'));
             }
         }
     }
     if ($this->getBackendType() == 'gallery') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Mage_Eav_Model_Entity_Attribute_Backend_Default');
         }
     }
     return parent::_beforeSave();
 }
开发者ID:natxetee,项目名称:magento2,代码行数:55,代码来源:Attribute.php

示例11: _beforeSave

 /**
  * Prepare data for save
  *
  * @return $this
  * @throws Exception
  */
 protected function _beforeSave()
 {
     // prevent overriding product data
     if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
         throw new Exception(__('The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code']));
     }
     /**
      * Check for maximum attribute_code length
      */
     if (isset($this->_data['attribute_code']) && !\Zend_Validate::is($this->_data['attribute_code'], 'StringLength', array('max' => self::ATTRIBUTE_CODE_MAX_LENGTH))) {
         throw new Exception(__('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH));
     }
     $defaultValue = $this->getDefaultValue();
     $hasDefaultValue = (string) $defaultValue != '';
     if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
         if (!\Zend_Locale_Format::isNumber($defaultValue, array('locale' => $this->_localeResolver->getLocaleCode()))) {
             throw new Exception(__('Invalid default decimal value'));
         }
         try {
             $filter = new \Zend_Filter_LocalizedToNormalized(array('locale' => $this->_localeResolver->getLocaleCode()));
             $this->setDefaultValue($filter->filter($defaultValue));
         } catch (\Exception $e) {
             throw new Exception(__('Invalid default decimal value'));
         }
     }
     if ($this->getBackendType() == 'datetime') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime');
         }
         if (!$this->getFrontendModel()) {
             $this->setFrontendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime');
         }
         // save default date value as timestamp
         if ($hasDefaultValue) {
             $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
             try {
                 $defaultValue = $this->_localeDate->date($defaultValue, $format, null, false)->toValue();
                 $this->setDefaultValue($defaultValue);
             } catch (\Exception $e) {
                 throw new Exception(__('Invalid default date'));
             }
         }
     }
     if ($this->getBackendType() == 'gallery') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend');
         }
     }
     return parent::_beforeSave();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:56,代码来源:Attribute.php

示例12: testIsNumberFailed

 /**
  * test if isNumberFailed
  * expected boolean
  */
 public function testIsNumberFailed()
 {
     $value = Zend_Locale_Format::isNumber('textwithoutnumber', 'de_AT');
     $this->assertEquals($value, FALSE, "FALSE expected");
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:9,代码来源:FormatTest.php

示例13: isNumber

 /** Checks if a given string is valid representation of a number in the current locale.
  * @return bool
  * @example http://www.concrete5.org/documentation/how-tos/developers/formatting-numbers/ See the Formatting numbers how-to for more details
  */
 public function isNumber($string)
 {
     return Zend_Locale_Format::isNumber($string, array('locale' => $this->getZendLocale()));
 }
开发者ID:ojalehto,项目名称:concrete5-legacy,代码行数:8,代码来源:number.php

示例14: _beforeSave

 protected function _beforeSave()
 {
     // prevent overriding product data
     if (isset($this->_data['attribute_code']) && Mage::getModel('catalog/product')->isReservedAttribute($this)) {
         Mage::throwException(Mage::helper('eav')->__('The attribute code \'%s\' is reserved by system. Please try another attribute code.', $this->_data['attribute_code']));
     }
     $defaultValue = $this->getDefaultValue();
     $hasDefaultValue = (string) $defaultValue != '';
     if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
         if (!Zend_Locale_Format::isNumber($defaultValue, array('locale' => Mage::app()->getLocale()->getLocaleCode()))) {
             throw new Exception('Invalid default decimal value.');
         }
         try {
             $filter = new Zend_Filter_LocalizedToNormalized(array('locale' => Mage::app()->getLocale()->getLocaleCode()));
             $this->setDefaultValue($filter->filter($defaultValue));
         } catch (Exception $e) {
             throw new Exception('Invalid default decimal value.');
         }
     }
     if ($this->getBackendType() == 'datetime') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('eav/entity_attribute_backend_datetime');
         }
         if (!$this->getFrontendModel()) {
             $this->setFrontendModel('eav/entity_attribute_frontend_datetime');
         }
         // save default date value as timestamp
         if ($hasDefaultValue) {
             $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
             try {
                 $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue();
                 $this->setDefaultValue($defaultValue);
             } catch (Exception $e) {
                 throw new Exception('Invalid default date.');
             }
         }
     }
     if ($this->getBackendType() == 'gallery') {
         if (!$this->getBackendModel()) {
             $this->setBackendModel('eav/entity_attribute_backend_media');
         }
     }
     return parent::_beforeSave();
 }
开发者ID:jpbender,项目名称:mage_virtual,代码行数:44,代码来源:Attribute.php


注:本文中的Zend_Locale_Format::isNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。