/**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $number = $this->getOption('number');
     if ($input->getValue() < $number) {
         throw new ValidationException(sprintf('value must be >= %d', $number));
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $name = $this->getOption('of');
     if (!$input->getValue() instanceof $name) {
         throw new ValidationException(sprintf('object is not an instance of %s', $name));
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $options = $this->getOption('options', FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6);
     if (!filter_var($input->getValue(), FILTER_VALIDATE_IP, $options)) {
         throw new ValidationException(sprintf('"%s" is not a valid IP address', $input->getValue()));
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $number = $this->getOption('length');
     $length = strlen($input->getValue());
     if ($length != $number) {
         throw new ValidationException(sprintf('value length is %d, expected %d', $length, $number));
     }
 }
Example #5
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $pattern = $this->getOption('pattern');
     $message = $this->getOption('message', sprintf('value does not match pattern %s', $pattern));
     if (!preg_match($this->getOption('pattern'), $input->getValue())) {
         throw new ValidationException($message);
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($this->getOption('convert') === false && !$input->getValue() instanceof \DateTime) {
         throw new ValidationException('value is not a DateTime object');
     }
     $input->replace(function ($value) {
         return Utils::toDateObject($value);
     });
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($this->getOption('convert') === false && trim($input->getValue()) !== $input->getValue()) {
         throw new ValidationException('value is not trimmed');
     }
     $input->replace(function ($value) {
         return trim($value);
     });
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($input->getValue() === null) {
         throw new ValidationException('value is required');
     }
     if (is_string($input->getValue()) && !strlen($input->getValue())) {
         throw new ValidationException('value is required');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $expected = $this->getOption('length');
     $actual = count($input->getValue());
     if ($actual != $expected) {
         $message = sprintf('array length is %d, while length of %d was expected', $actual, $expected);
         throw new ValidationException($message);
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $expected = $this->getOption('length');
     $actual = count($input->getValue());
     if ($actual > $expected) {
         $message = sprintf('array needs to have at most %d items', $expected);
         throw new ValidationException($message);
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($this->getOption('convert') === false && !ctype_lower($input->getValue())) {
         throw new ValidationException('value must be lowercase');
     }
     $input->replace(function ($value) {
         return strtolower($value);
     });
 }
Example #12
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($input->getValue() instanceof \DateTime) {
         return;
     }
     if (is_string($input->getValue()) && false !== strtotime($input->getValue())) {
         return;
     }
     throw new ValidationException('value is not a date');
 }
Example #13
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     $options = $this->getOption('options');
     if ($options == null && !filter_var($input->getValue(), FILTER_VALIDATE_URL)) {
         throw new ValidationException(sprintf('"%s" is not a valid URI', $input->getValue()));
     }
     if ($options !== null && !filter_var($input->getValue(), FILTER_VALIDATE_URL, $options)) {
         throw new ValidationException(sprintf('"%s" is not a valid URI', $input->getValue()));
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     foreach ($this->getOption('options') as $schema) {
         try {
             $input->replace(function ($value) use($schema) {
                 return V::attempt($value, $schema);
             });
             return;
         } catch (ValidationException $e) {
         }
     }
     throw new ValidationException('none of the alternatives matched');
 }
 /**
  * @param InputValue $input
  * @param $key
  * @param AbstractSchema $schema
  * @throws ValidationException
  */
 private function validateAndReplaceKey(InputValue $input, $key, AbstractSchema $schema)
 {
     try {
         $input->replace(function ($value) use($key, $schema) {
             $value[$key] = V::attempt($value[$key], $schema);
             return $value;
         });
         if ($schema->getOption('strip')) {
             $input->replace(function ($value) use($key) {
                 unset($value[$key]);
                 return $value;
             });
         }
     } catch (ValidationException $e) {
         throw new ValidationException(sprintf('key "%s" is invalid, because [ %s ]', $key, $e->getMessage()));
     }
 }
 public function testCases()
 {
     $input = new InputValue('foo');
     $this->assertEquals('foo', $input->getValue());
     $input->setValue('bar');
     $this->assertEquals('bar', $input->getValue());
     $input->setValue(2);
     $input->replace(function ($value) {
         return $value * 2;
     });
     $this->assertEquals(4, $input->getValue());
 }
Example #17
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_float($input->getValue())) {
         throw new ValidationException('value is not a float');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($input->getValue() !== false) {
         throw new ValidationException('value is not FALSE');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (count($input->getValue()) === 0) {
         throw new ValidationException('value is an empty array');
     }
 }
Example #20
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_array($input->getValue())) {
         throw new ValidationException('value is not an array');
     }
 }
Example #21
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!filter_var($input->getValue(), FILTER_VALIDATE_EMAIL)) {
         throw new ValidationException(sprintf('"%s" is not a valid email', $input->getValue()));
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_resource($input->getValue())) {
         throw new ValidationException('value is not a resource');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_callable($input->getValue())) {
         throw new ValidationException('value is not callable');
     }
 }
 /**
  * @param InputValue $input
  */
 public function process(InputValue $input)
 {
     $input->replace(function ($value) {
         return preg_replace($this->getOption('pattern'), $this->getOption('replace'), $value);
     });
 }
Example #25
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!in_array($input->getValue(), $this->getOption('allowed'))) {
         throw new ValidationException(sprintf('value "%s" is not allowed', $input->getValue()));
     }
 }
Example #26
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_string($input->getValue())) {
         throw new ValidationException('value is not a string');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_bool($input->getValue())) {
         throw new ValidationException('value is not a boolean');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!ctype_alnum($input->getValue())) {
         throw new ValidationException('value contains not alphanumeric chars');
     }
 }
Example #29
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_integer($input->getValue()) && !is_float($input->getValue())) {
         throw new ValidationException('value is not a number');
     }
 }
Example #30
0
 /**
  * @param InputValue $input
  */
 public function process(InputValue $input)
 {
     $input->replace(function ($value) {
         return str_replace($this->getOption('search'), $this->getOption('replace'), $value);
     });
 }