• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Validate/Float.php

00001 <?php
00025 require_once 'Zend/Validate/Abstract.php';
00026 
00030 require_once 'Zend/Locale/Format.php';
00031 
00038 class Zend_Validate_Float extends Zend_Validate_Abstract
00039 {
00040     const INVALID   = 'floatInvalid';
00041     const NOT_FLOAT = 'notFloat';
00042 
00046     protected $_messageTemplates = array(
00047         self::INVALID   => "Invalid type given, value should be float, string, or integer",
00048         self::NOT_FLOAT => "'%value%' does not appear to be a float"
00049     );
00050 
00051     protected $_locale;
00052 
00058     public function __construct($locale = null)
00059     {
00060         if ($locale !== null) {
00061             $this->setLocale($locale);
00062         }
00063     }
00064 
00068     public function getLocale()
00069     {
00070         return $this->_locale;
00071     }
00072 
00078     public function setLocale($locale = null)
00079     {
00080         require_once 'Zend/Locale.php';
00081         $this->_locale = Zend_Locale::findLocale($locale);
00082         return $this;
00083     }
00084 
00093     public function isValid($value)
00094     {
00095         if (!is_string($value) && !is_int($value) && !is_float($value)) {
00096             $this->_error(self::INVALID);
00097             return false;
00098         }
00099 
00100         $this->_setValue($value);
00101         if ($this->_locale === null) {
00102             $locale        = localeconv();
00103             $valueFiltered = str_replace($locale['thousands_sep'], '', (string) $value);
00104             $valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
00105 
00106             if (strval(floatval($valueFiltered)) != $valueFiltered) {
00107                 $this->_error(self::NOT_FLOAT);
00108                 return false;
00109             }
00110 
00111         } else {
00112             try {
00113                 if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) &&
00114                     !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
00115                     $this->_error(self::NOT_FLOAT);
00116                     return false;
00117                 }
00118             } catch (Zend_Locale_Exception $e) {
00119                 $this->_error(self::NOT_FLOAT);
00120                 return false;
00121             }
00122         }
00123 
00124         return true;
00125     }
00126 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2