/** * @param mixed $value * @param string $classBaseName * @param array $args OPTIONAL * @param mixed $namespaces OPTIONAL * @return boolean * @throws Postman_Zend_Validate_Exception */ public static function is($value, $classBaseName, array $args = array(), $namespaces = array()) { $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Postman_Zend_Validate')); $className = ucfirst($classBaseName); try { if (!class_exists($className, false)) { require_once 'Zend/Loader.php'; foreach ($namespaces as $namespace) { $class = $namespace . '_' . $className; $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; if (Postman_Zend_Loader::isReadable($file)) { Postman_Zend_Loader::loadClass($class); $className = $class; break; } } } $class = new ReflectionClass($className); if ($class->implementsInterface('Postman_Zend_Validate_Interface')) { if ($class->hasMethod('__construct')) { $keys = array_keys($args); $numeric = false; foreach ($keys as $key) { if (is_numeric($key)) { $numeric = true; break; } } if ($numeric) { $object = $class->newInstanceArgs($args); } else { $object = $class->newInstance($args); } } else { $object = $class->newInstance(); } return $object->isValid($value); } } catch (Postman_Zend_Validate_Exception $ze) { // if there is an exception while validating throw it throw $ze; } catch (Exception $e) { // fallthrough and continue for missing validation classes } require_once 'Zend/Validate/Exception.php'; throw new Postman_Zend_Validate_Exception("Validate class not found from basename '{$classBaseName}'"); }
/** * Sets a new barcode adapter * * @param string|Postman_Zend_Validate_Barcode $adapter Barcode adapter to use * @param array $options Options for this adapter * @return $this * @throws Postman_Zend_Validate_Exception */ public function setAdapter($adapter, $options = null) { $adapter = ucfirst(strtolower($adapter)); require_once 'Zend/Loader.php'; if (Postman_Zend_Loader::isReadable('Zend/Validate/Barcode/' . $adapter . '.php')) { $adapter = 'Postman_Zend_Validate_Barcode_' . $adapter; } if (!class_exists($adapter)) { Postman_Zend_Loader::loadClass($adapter); } $this->_adapter = new $adapter($options); if (!$this->_adapter instanceof Postman_Zend_Validate_Barcode_AdapterInterface) { require_once 'Zend/Validate/Exception.php'; throw new Postman_Zend_Validate_Exception("Adapter " . $adapter . " does not implement Postman_Zend_Validate_Barcode_AdapterInterface"); } return $this; }