/**
     * Constructs a new validator, initializing the minimum valid value.
     *
     * @param Zikula_ServiceManager $serviceManager The current service manager instance.
     * @param integer               $value          The minimum valid value for the field data.
     * @param string                $errorMessage   The error message to return if the field data is not valid.
     *
     * @throws InvalidArgumentException If the minimum value specified is not an integer.
     */
    public function __construct(Zikula_ServiceManager $serviceManager, $value, $errorMessage = null)
    {
        parent::__construct($serviceManager, $errorMessage);

        if (!isset($value) || !is_int($value) || ($value < 0)) {
            throw new InvalidArgumentException($this->__('An invalid integer value was received.'));
        }

        $this->value = $value;
    }
    /**
     * Constructs the validator, initializing the regular expression.
     *
     * @param Zikula_ServiceManager $serviceManager    The current service manager instance.
     * @param string                $regularExpression The PCRE regular expression against which to validate the data.
     * @param string                $errorMessage      The error message to return if the data does not match the expression.
     *
     * @throws InvalidArgumentException Thrown if the regular expression is not valid.
     */
    public function __construct(Zikula_ServiceManager $serviceManager, $regularExpression, $errorMessage = null)
    {
        parent::__construct($serviceManager, $errorMessage);

        if (!isset($regularExpression) || !is_string($regularExpression) || empty($regularExpression)) {
            throw new InvalidArgumentException($this->__('An invalid regular expression was recieved.'));
        }

        $this->regularExpression = $regularExpression;
    }
예제 #3
0
    /**
     * Constructs a new validator, initializing the maximum valid string length value.
     *
     * @param Zikula_ServiceManager $serviceManager The current service manager instance.
     * @param integer               $length         The maximum valid length for the string value.
     * @param string                $errorMessage   The error message to return if the string data exceeds the maximum length.
     *
     * @throws InvalidArgumentException Thrown if the maximum string length value is not an integer or is less than zero.
     */
    public function __construct(Zikula_ServiceManager $serviceManager, $length, $errorMessage = null)
    {
        parent::__construct($serviceManager, $errorMessage);

        if (!isset($length) || !is_int($length) || ($length < 0)) {
            throw new InvalidArgumentException($this->__('An invalid string length was received.'));
        }

        $this->length = $length;
    }
예제 #4
0
    /**
     * Creates a new instance of this validator, intializing the list of valid integers.
     *
     * @param Zikula_ServiceManager $serviceManager The current service manager.
     * @param array                 $validIntegers  An array containing a list of integers considered to be valid for the field's data contents.
     * @param type                  $errorMessage   The message to return if the data is not valid.
     *
     * @throws InvalidArgumentException Thrown if the list of valid integer numerics is invalid, or if it contains an invalid value.
     */
    public function __construct(Zikula_ServiceManager $serviceManager, array $validIntegers, $errorMessage = null)
    {
        parent::__construct($serviceManager, $errorMessage);

        if (empty($validIntegers)) {
            throw new InvalidArgumentException($this->__('An invalid list of valid integers was recieved.'));
        }

        foreach ($validIntegers as $validInteger) {
            if (isset($validInteger) && is_int($validInteger)) {
                $this->validIntegers[$validInteger] = $validInteger;
            } else {
                throw new InvalidArgumentException($this->__('An invalid value was received in the list of valid integers.'));
            }
        }
    }