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

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

00001 <?php
00025 require_once 'Zend/Validate/Interface.php';
00026 
00033 class Zend_Validate implements Zend_Validate_Interface
00034 {
00040     protected $_validators = array();
00041 
00047     protected $_messages = array();
00048 
00054     protected static $_defaultNamespaces = array();
00055 
00062     protected $_errors = array();
00063 
00074     public function addValidator(Zend_Validate_Interface $validator, $breakChainOnFailure = false)
00075     {
00076         $this->_validators[] = array(
00077             'instance' => $validator,
00078             'breakChainOnFailure' => (boolean) $breakChainOnFailure
00079             );
00080         return $this;
00081     }
00082 
00091     public function isValid($value)
00092     {
00093         $this->_messages = array();
00094         $this->_errors   = array();
00095         $result = true;
00096         foreach ($this->_validators as $element) {
00097             $validator = $element['instance'];
00098             if ($validator->isValid($value)) {
00099                 continue;
00100             }
00101             $result = false;
00102             $messages = $validator->getMessages();
00103             $this->_messages = array_merge($this->_messages, $messages);
00104             $this->_errors   = array_merge($this->_errors,   array_keys($messages));
00105             if ($element['breakChainOnFailure']) {
00106                 break;
00107             }
00108         }
00109         return $result;
00110     }
00111 
00119     public function getMessages()
00120     {
00121         return $this->_messages;
00122     }
00123 
00132     public function getErrors()
00133     {
00134         return $this->_errors;
00135     }
00136 
00142     public static function getDefaultNamespaces()
00143     {
00144         return self::$_defaultNamespaces;
00145     }
00146 
00153     public static function setDefaultNamespaces($namespace)
00154     {
00155         if (!is_array($namespace)) {
00156             $namespace = array((string) $namespace);
00157         }
00158 
00159         self::$_defaultNamespaces = $namespace;
00160     }
00161 
00168     public static function addDefaultNamespaces($namespace)
00169     {
00170         if (!is_array($namespace)) {
00171             $namespace = array((string) $namespace);
00172         }
00173 
00174         self::$_defaultNamespaces = array_unique(array_merge(self::$_defaultNamespaces, $namespace));
00175     }
00176 
00182     public static function hasDefaultNamespaces()
00183     {
00184         return (!empty(self::$_defaultNamespaces));
00185     }
00186 
00195     public static function is($value, $classBaseName, array $args = array(), $namespaces = array())
00196     {
00197         $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Validate'));
00198         foreach ($namespaces as $namespace) {
00199             $className = $namespace . '_' . ucfirst($classBaseName);
00200             try {
00201                 if (!class_exists($className)) {
00202                     require_once 'Zend/Loader.php';
00203                     Zend_Loader::loadClass($className);
00204                 }
00205                 $class = new ReflectionClass($className);
00206                 if ($class->implementsInterface('Zend_Validate_Interface')) {
00207                     if ($class->hasMethod('__construct')) {
00208                         $object = $class->newInstanceArgs($args);
00209                     } else {
00210                         $object = $class->newInstance();
00211                     }
00212                     return $object->isValid($value);
00213                 }
00214             } catch (Zend_Validate_Exception $ze) {
00215                 // if there is an exception while validating throw it
00216                 throw $ze;
00217             } catch (Zend_Exception $ze) {
00218                 // fallthrough and continue for missing validation classes
00219             }
00220         }
00221         require_once 'Zend/Validate/Exception.php';
00222         throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'");
00223     }
00224 
00230     public static function getMessageLength()
00231     {
00232         require_once 'Zend/Validate/Abstract.php';
00233         return Zend_Validate_Abstract::getMessageLength();
00234     }
00235 
00241     public static function setMessageLength($length = -1)
00242     {
00243         require_once 'Zend/Validate/Abstract.php';
00244         Zend_Validate_Abstract::setMessageLength($length);
00245     }
00246 }

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