Zend_Validate_Exception example


    public function setMin($min)
    {
        if (null !== $this->_max && $min > $this->_max) {
            /** * @see Zend_Validate_Exception */
            throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum length, but $min >"
                                            . " $this->_max");
        }
        $this->_min = max(0, (integer) $min);
        return $this;
    }

    /** * Returns the max option * * @return integer|null */
    
$temp['max'] = array_shift($options);
            }

            if (!empty($options)) {
                $temp['inclusive'] = array_shift($options);
            }

            $options = $temp;
        }

        if (!array_key_exists('min', $options) || !array_key_exists('max', $options)) {
            throw new Zend_Validate_Exception("Missing option. 'min' and 'max' has to be given");
        }

        if (!array_key_exists('inclusive', $options)) {
            $options['inclusive'] = true;
        }

        $this->setMin($options['min'])
             ->setMax($options['max'])
             ->setInclusive($options['inclusive']);
    }

    

    public function __construct($options = array())
    {
        // prepare options         if ($options instanceof Zend_Config) {
            $options = $options->toArray();
        }
        if (!is_array($options)) {
            /** * @see Zend_Validate_Exception */
            throw new Zend_Validate_Exception('Invalid options provided.');
        }

        // set type         if (array_key_exists('type', $options)) {
            $this->setType($options['type']);
        }

        // set separator         if (array_key_exists('separator', $options)) {
            $this->setSeparator($options['separator']);
        }
    }
public function setOptions($options)
    {
        if (array_key_exists('allowipv6', $options)) {
            $this->_options['allowipv6'] = (boolean) $options['allowipv6'];
        }

        if (array_key_exists('allowipv4', $options)) {
            $this->_options['allowipv4'] = (boolean) $options['allowipv4'];
        }

        if (!$this->_options['allowipv4'] && !$this->_options['allowipv6']) {
            throw new Zend_Validate_Exception('Nothing to validate. Check your options');
        }

        return $this;
    }

    /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is a valid IP address * * @param mixed $value * @return boolean */
 else if (in_array($value$this->_constants)) {
                    $detected += array_search($value$this->_constants);
                }
            }

            $type = $detected;
        } else if (is_string($type) && in_array($type$this->_constants)) {
            $type = array_search($type$this->_constants);
        }

        if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
            throw new Zend_Validate_Exception('Unknown type');
        }

        $this->_type = $type;
        return $this;
    }

    /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value is not an empty value. * * @param string $value * @return boolean */
if (array_key_exists('options', $adapter)) {
                $options = $adapter['options'];
            }

            if (array_key_exists('checksum', $adapter)) {
                $checksum = $adapter['checksum'];
            }

            if (array_key_exists('adapter', $adapter)) {
                $adapter = $adapter['adapter'];
            } else {
                throw new Zend_Validate_Exception("Missing option 'adapter'");
            }
        }

        $this->setAdapter($adapter$options);
        if ($checksum !== null) {
            $this->setChecksum($checksum);
        }
    }

    /** * Returns the set adapter * * @return Zend_Validate_Barcode_BarcodeAdapter */
public function setMessage($messageString$messageKey = null)
    {
        if ($messageKey === null) {
            $keys = array_keys($this->_messageTemplates);
            foreach($keys as $key) {
                $this->setMessage($messageString$key);
            }
            return $this;
        }

        if (!isset($this->_messageTemplates[$messageKey])) {
            throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
        }

        $this->_messageTemplates[$messageKey] = $messageString;
        return $this;
    }

    /** * Sets validation failure message templates given as an array, where the array keys are the message keys, * and the array values are the message template strings. * * @param array $messages * @return Zend_Validate_Abstract */
return $this->_service;
    }

    /** * Sets a new callback for service validation * * @param unknown_type $service */
    public function setService($service)
    {
        if (!is_callable($service)) {
            throw new Zend_Validate_Exception('Invalid callback given');
        }

        $this->_service = $service;
        return $this;
    }

    /** * Defined by Zend_Validate_Interface * * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum) * * @param string $value * @return boolean */

    public function setTranslator($translator = null)
    {
        if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
            $this->_translator = $translator;
        } elseif ($translator instanceof Zend_Translate) {
            $this->_translator = $translator->getAdapter();
        } else {
            throw new Zend_Validate_Exception('Invalid translator specified');
        }

        return $this;
    }

    /** * Return translation object * * @return Zend_Translate_Adapter|null */
    public function getTranslator()
    {

    public function __construct($min)
    {
        if ($min instanceof Zend_Config) {
            $min = $min->toArray();
        }

        if (is_array($min)) {
            if (array_key_exists('min', $min)) {
                $min = $min['min'];
            } else {
                throw new Zend_Validate_Exception("Missing option 'min'");
            }
        }

        $this->setMin($min);
    }

    /** * Returns the min option * * @return mixed */
    


                return $object->isValid($value);
            }
        } catch (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         }

        throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'");
    }

    /** * Returns the maximum allowed message length * * @return integer */
    public static function getMessageLength()
    {
        return Zend_Validate_Abstract::getMessageLength();
    }

    
/** * Sets validator options * * @param array|Zend_Config $haystack * @return void */
    public function __construct($options)
    {
        if ($options instanceof Zend_Config) {
            $options = $options->toArray();
        } else if (!is_array($options)) {
            throw new Zend_Validate_Exception('Array expected as parameter');
        } else {
            $count = func_num_args();
            $temp  = array();
            if ($count > 1) {
                $temp['haystack'] = func_get_arg(0);
                $temp['strict']   = func_get_arg(1);
                $options = $temp;
            } else {
                $temp = func_get_arg(0);
                if (!array_key_exists('haystack', $options)) {
                    $options = array();
                    
/** * Sets the locale option * * @param string|Zend_Locale $locale * @return Zend_Validate_Date provides a fluent interface */
    public function setLocale($locale = null)
    {
        if ($locale !== false) {
            $locale = Zend_Locale::findLocale($locale);
            if (strlen($locale) < 4) {
                throw new Zend_Validate_Exception('Region must be given for IBAN validation');
            }
        }

        $this->_locale = $locale;
        return $this;
    }

    /** * Defined by Zend_Validate_Interface * * Returns true if $value is a valid IBAN * * @param string $value * @return boolean */

    public function __construct($max)
    {
        if ($max instanceof Zend_Config) {
            $max = $max->toArray();
        }

        if (is_array($max)) {
            if (array_key_exists('max', $max)) {
                $max = $max['max'];
            } else {
                throw new Zend_Validate_Exception("Missing option 'max'");
            }
        }

        $this->setMax($max);
    }

    /** * Returns the max option * * @return mixed */
    
if (array_key_exists('format', $options)) {
                $this->setFormat($options['format']);
            }
        } elseif ($options instanceof Zend_Locale || is_string($options)) {
            // Received Locale object or string locale             $this->setLocale($options);
        }

        $format = $this->getFormat();
        if (empty($format)) {
            throw new Zend_Validate_Exception("A postcode-format string has to be given for validation");
        }
    }

    /** * Returns the set locale * * @return string|Zend_Locale The set locale */
    public function getLocale()
    {
        return $this->_locale;
    }
Home | Imprint | This part of the site doesn't use cookies.