Example #1
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     $value = $input->val();
     if (!empty($value) && filter_var($value, static::FILTER) === false) {
         throw new InvalidValueException(sprintf(static::$error_message, $value));
     }
 }
Example #2
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     $value = $input->val();
     if (!empty($value) && !preg_match('/^#[A-Fa-f0-9]{6}$/', $value)) {
         throw new InvalidValueException(sprintf(static::$error_message, $value));
     }
 }
Example #3
0
 /**
  * Validates the datetime input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validateDatetime(InputInterface $input)
 {
     $value = $input->val();
     $attr = $input->attr('max');
     if (!empty($attr) && strtotime($value) > strtotime($attr)) {
         throw new InvalidValueException(sprintf(static::$error_message, $attr));
     }
 }
Example #4
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     if (!($value = $input->val())) {
         return;
     }
     if (!($date = date_create($value))) {
         throw new InvalidValueException(sprintf(static::$error_message, $value));
     }
 }
Example #5
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     if (!($value = $input->val())) {
         return;
     }
     if ($input->attr('multiple')) {
         if (array_keys(array_diff_key(array_flip($value), $input->options()))) {
             throw new InvalidValueException(sprintf(static::$error_message));
         }
     } elseif (!isset($input[$value])) {
         throw new InvalidValueException(sprintf(static::$error_message));
     }
 }
Example #6
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     $value = $input->val();
     $error = null;
     if ($value instanceof UploadedFileInterface) {
         $error = $value->getError();
     } elseif (isset($value['error'])) {
         $error = $value['error'];
     }
     if ($error !== null && isset(self::$error_message[$error])) {
         throw new InvalidValueException(sprintf(static::$error_message[$error]));
     }
 }
Example #7
0
 /**
  * Validates the input value according to this attribute
  *
  * @param InputInterface $input The input to validate
  *
  * @return string|true True if its valid, string with the error if not
  */
 public static function validate($input)
 {
     $value = $input->val();
     if (empty($value['tmp_name'])) {
         return true;
     }
     $attr = $input->attr('accept');
     $accept = array_map('trim', explode(',', $attr));
     $filename = $value['tmp_name'];
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $filename);
     finfo_close($finfo);
     return array_search($mime, $accept) !== false ? true : sprintf(static::$error_message, $attr);
 }
Example #8
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     $value = $input->val();
     //Psr UploadeFileInterface validation
     if ($value instanceof UploadedFileInterface) {
         if ($value->getError() === UPLOAD_ERR_NO_FILE) {
             return;
         }
         return static::validateMime($value->getStream()->getMetadata('uri'), $input->attr('accept'));
     }
     if (empty($value['tmp_name'])) {
         return true;
     }
     static::validateMime($value['tmp_name'], $input->attr('accept'));
 }
Example #9
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     $value = $input->val();
     if ($input->attr('type') === 'file') {
         if ($value instanceof UploadedFileInterface) {
             $value = $value->getSize();
         } else {
             $value = isset($value['size']) ? $value['size'] : null;
         }
     }
     $attr = $input->attr('required');
     if (!empty($attr) && empty($value) && strlen($value) === 0) {
         throw new InvalidValueException(sprintf(static::$error_message, $attr));
     }
 }
Example #10
0
 /**
  * Validates the input value according to this attribute.
  *
  * @param InputInterface $input The input to validate
  *
  * @throws InvalidValueException If the value is not valid
  */
 public static function validate(InputInterface $input)
 {
     $value = $input->val();
     if ($input->attr('type') === 'file') {
         if ($value instanceof UploadedFileInterface) {
             $value = $value->getClientFilename();
         } else {
             $value = isset($value['name']) ? $value['name'] : null;
         }
     }
     $attr = str_replace('/', '\\/', $input->attr('pattern'));
     if (!empty($attr) && !empty($value) && !filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^{$attr}\$/")))) {
         throw new InvalidValueException(sprintf(static::$error_message, $attr));
     }
 }
Example #11
0
 /**
  * Validates the input value according to this attribute
  *
  * @param InputInterface $input The input to validate
  *
  * @return string|true True if its valid, string with the error if not
  */
 public static function validate($input)
 {
     $value = $input->val();
     $attr = $input->attr('max');
     return empty($attr) || $value <= $attr ? true : sprintf(static::$error_message, $attr);
 }