/** * Construct a new minimum maximum validator * @param array $options options for the validator * @return null * @throws zibo\ZiboException when no minimum option or maximum option is provided * @throws zibo\ZiboException when the minimum or maximum is not a numeric value */ public function __construct(array $options = array()) { parent::__construct($options); if (array_key_exists(self::OPTION_ERROR_REQUIRED, $options)) { $this->errorCode = $options[self::OPTION_ERROR_REQUIRED]; } else { $this->errorCode = self::CODE; } }
/** * Construct a new regular expression validator * @param array $options options for this validator * @return null * @throws zibo\ZiboException when the regex option is empty or not a string */ public function __construct(array $options = array()) { parent::__construct($options); $this->isRequired = true; if (isset($options[self::OPTION_REQUIRED])) { $this->isRequired = $options[self::OPTION_REQUIRED]; } if (array_key_exists(self::OPTION_ERROR_NUMERIC, $options)) { $this->errorCode = $options[self::OPTION_ERROR_NUMERIC]; } else { $this->errorCode = self::CODE; } }
/** * Construct a new file extension validator * @param array $options options for this validator * @return null */ public function __construct(array $options = array()) { parent::__construct($options); $this->extensions = array(); if (isset($options[self::OPTION_EXTENSIONS])) { $extensions = explode(',', $options[self::OPTION_EXTENSIONS]); foreach ($extensions as $extension) { $extension = trim($extension); $this->extensions[$extension] = $extension; } } $this->isRequired = true; if (isset($options[self::OPTION_REQUIRED])) { $this->isRequired = $options[self::OPTION_REQUIRED]; } }
/** * Construct a new regular expression validator * @param array $options options for this validator * @return null * @throws zibo\ZiboException when the regex option is empty or not a string */ public function __construct(array $options = array()) { parent::__construct($options); $this->isRequired = true; if (isset($options[self::OPTION_REQUIRED])) { $this->isRequired = $options[self::OPTION_REQUIRED]; } if (isset($options[self::OPTION_CLASS])) { $class = $options[self::OPTION_CLASS]; try { $classReflection = new ReflectionClass($class); } catch (Exception $e) { throw new ZiboException('Needed class/interface ' . $class . ' not found', 0, $e); } $this->class = $classReflection; } }
/** * Construct a new regular expression validator * @param array $options options for this validator * @return null * @throws zibo\ZiboException when the regex option is empty or not a string */ public function __construct(array $options = array()) { parent::__construct($options); if (!isset($options[self::OPTION_REGEX])) { throw new ZiboException('No regular expression provided through the options. Use option ' . self::OPTION_REGEX); } if (String::isEmpty($options[self::OPTION_REGEX])) { throw new ZiboException('Provided regular expression is empty'); } $this->isRequired = true; if (isset($options[self::OPTION_REQUIRED])) { $this->isRequired = $options[self::OPTION_REQUIRED]; } $this->regex = $options[self::OPTION_REGEX]; $this->code = self::CODE; if (isset($options['message'])) { $this->code = $options['message']; } $this->message = 'Field does not match ' . $this->regex; }
/** * Construct a new image validator * @param array $options options for this validator * @return null */ public function __construct(array $options = array()) { parent::__construct($options); $this->isRequired = false; if (array_key_exists(self::OPTION_REQUIRED, $options)) { $this->isRequired = $options[self::OPTION_REQUIRED]; } $this->minHeight = null; if (array_key_exists(self::OPTION_HEIGHT_MIN, $options)) { $this->minHeight = $options[self::OPTION_HEIGHT_MIN]; if ($this->minHeight != '0' && Number::isNegative($this->minHeight)) { throw new ZiboException('Provided minimum height is invalid: ' . $this->minHeight); } } $this->minWidth = null; if (array_key_exists(self::OPTION_WIDTH_MIN, $options)) { $this->minWidth = $options[self::OPTION_WIDTH_MIN]; if ($this->minWidth != '0' && Number::isNegative($this->minWidth)) { throw new ZiboException('Provided maximum width is invalid: ' . $this->minWidth); } } $this->maxHeight = null; if (array_key_exists(self::OPTION_HEIGHT_MAX, $options)) { $this->maxHeight = $options[self::OPTION_HEIGHT_MAX]; if ($this->maxHeight != '0' && Number::isNegative($this->maxHeight)) { throw new ZiboException('Provided maximum height is invalid: ' . $this->maxHeight); } } $this->maxWidth = null; if (array_key_exists(self::OPTION_WIDTH_MAX, $options)) { $this->maxWidth = $options[self::OPTION_WIDTH_MAX]; if ($this->maxWidth != '0' && Number::isNegative($this->maxWidth)) { throw new ZiboException('Provided maximum width is invalid: ' . $this->maxWidth); } } }