コード例 #1
0
ファイル: Barcode.php プロジェクト: DanMaiman/Awfulkid
 /**
  * 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;
 }
コード例 #2
0
ファイル: Validate.php プロジェクト: DanMaiman/Awfulkid
 /**
  * @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}'");
 }
コード例 #3
0
ファイル: Registry.php プロジェクト: DanMaiman/Awfulkid
 /**
  * Set the class name to use for the default registry instance.
  * Does not affect the currently initialized instance, it only applies
  * for the next time you instantiate.
  *
  * @param string $registryClassName
  * @return void
  * @throws Postman_Zend_Exception if the registry is initialized or if the
  *   class name is not valid.
  */
 public static function setClassName($registryClassName = 'Postman_Zend_Registry')
 {
     if (self::$_registry !== null) {
         require_once 'Zend/Exception.php';
         throw new Postman_Zend_Exception('Registry is already initialized');
     }
     if (!is_string($registryClassName)) {
         require_once 'Zend/Exception.php';
         throw new Postman_Zend_Exception("Argument is not a class name");
     }
     /**
      * @see Postman_Zend_Loader
      */
     if (!class_exists($registryClassName)) {
         require_once 'Zend/Loader.php';
         Postman_Zend_Loader::loadClass($registryClassName);
     }
     self::$_registryClassName = $registryClassName;
 }