Advertisement
linccce

Validator class not found

Nov 30th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1.     /**
  2.      * @param  mixed    $value
  3.      * @param  string   $classBaseName
  4.      * @param  array    $args          OPTIONAL
  5.      * @param  mixed    $namespaces    OPTIONAL
  6.      * @return boolean
  7.      * @throws Zend_Validate_Exception
  8.      */
  9.     public static function is($value, $classBaseName, array $args = array(), $namespaces = array())
  10.     {
  11.         $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Validate'));
  12.         $className  = ucfirst($classBaseName);
  13.         try {
  14.             if (!class_exists($className, false)) {
  15.                 #require_once 'Zend/Loader.php';
  16.                foreach($namespaces as $namespace) {
  17.                     $class = $namespace . '_' . $className;
  18.                     $file  = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
  19.                     if (Zend_Loader::isReadable($file)) {
  20.                         Zend_Loader::loadClass($class);
  21.                         $className = $class;
  22.                         break;
  23.                     }
  24.                 }
  25.             }
  26.  
  27.             $class = new ReflectionClass($className);
  28.             if ($class->implementsInterface('Zend_Validate_Interface')) {
  29.                 if ($class->hasMethod('__construct')) {
  30.                     $keys    = array_keys($args);
  31.                     $numeric = false;
  32.                     foreach($keys as $key) {
  33.                         if (is_numeric($key)) {
  34.                             $numeric = true;
  35.                             break;
  36.                         }
  37.                     }
  38.  
  39.                     if ($numeric) {
  40.                         $object = $class->newInstanceArgs($args);
  41.                     } else {
  42.                         $object = $class->newInstance($args);
  43.                     }
  44.                 } else {
  45.                     $object = $class->newInstance();
  46.                 }
  47.  
  48.                 return $object->isValid($value);
  49.             }
  50.         } catch (Zend_Validate_Exception $ze) {
  51.             // if there is an exception while validating throw it
  52.             throw $ze;
  53.         } catch (Exception $e) {
  54.             // fallthrough and continue for missing validation classes
  55.         }
  56.  
  57.         #require_once 'Zend/Validate/Exception.php';
  58.        throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'");
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement