Exemplo n.º 1
0
 /**
  * Sets validator options
  *
  * @param string|array|Postman_Zend_Config $options OPTIONAL
  */
 public function __construct($options = array())
 {
     if ($options instanceof Postman_Zend_Config) {
         $options = $options->toArray();
     } else {
         if (!is_array($options)) {
             $options = func_get_args();
             $temp['format'] = array_shift($options);
             if (!empty($options)) {
                 $temp['locale'] = array_shift($options);
             }
             $options = $temp;
         }
     }
     if (array_key_exists('format', $options)) {
         $this->setFormat($options['format']);
     }
     if (!array_key_exists('locale', $options)) {
         require_once 'Zend/Registry.php';
         if (Postman_Zend_Registry::isRegistered('Postman_Zend_Locale')) {
             $options['locale'] = Postman_Zend_Registry::get('Postman_Zend_Locale');
         }
     }
     if (array_key_exists('locale', $options)) {
         $this->setLocale($options['locale']);
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor for the integer validator
  *
  * Accepts either a string locale, a Postman_Zend_Locale object, or an array or
  * Postman_Zend_Config object containing the keys "locale" and/or "format".
  *
  * @param string|Postman_Zend_Locale|array|Postman_Zend_Config $options
  * @throws Postman_Zend_Validate_Exception On empty format
  */
 public function __construct($options = null)
 {
     if ($options instanceof Postman_Zend_Config) {
         $options = $options->toArray();
     }
     if (empty($options)) {
         require_once 'Zend/Registry.php';
         if (Postman_Zend_Registry::isRegistered('Postman_Zend_Locale')) {
             $this->setLocale(Postman_Zend_Registry::get('Postman_Zend_Locale'));
         }
     } elseif (is_array($options)) {
         // Received
         if (array_key_exists('locale', $options)) {
             $this->setLocale($options['locale']);
         }
         if (array_key_exists('format', $options)) {
             $this->setFormat($options['format']);
         }
     } elseif ($options instanceof Postman_Zend_Locale || is_string($options)) {
         // Received Locale object or string locale
         $this->setLocale($options);
     }
     $format = $this->getFormat();
     if (empty($format)) {
         require_once 'Zend/Validate/Exception.php';
         throw new Postman_Zend_Validate_Exception("A postcode-format string has to be given for validation");
     }
 }
Exemplo n.º 3
0
 /**
  * Returns TRUE if the $index is a named value in the registry,
  * or FALSE if $index was not found in the registry.
  *
  * @param  string $index
  * @return boolean
  */
 public static function isRegistered($index)
 {
     if (self::$_registry === null) {
         return false;
     }
     return self::$_registry->offsetExists($index);
 }
Exemplo n.º 4
0
 /**
  * Constructor for the float validator
  *
  * @param string|Postman_Zend_Config|Postman_Zend_Locale $locale
  */
 public function __construct($locale = null)
 {
     if ($locale instanceof Postman_Zend_Config) {
         $locale = $locale->toArray();
     }
     if (is_array($locale)) {
         if (array_key_exists('locale', $locale)) {
             $locale = $locale['locale'];
         } else {
             $locale = null;
         }
     }
     if (empty($locale)) {
         require_once 'Zend/Registry.php';
         if (Postman_Zend_Registry::isRegistered('Postman_Zend_Locale')) {
             $locale = Postman_Zend_Registry::get('Postman_Zend_Locale');
         }
     }
     $this->setLocale($locale);
 }