Пример #1
0
 /**
  * @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()));
     }
 }
Пример #2
0
 /**
  * @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);
     });
 }
Пример #3
0
 /**
  * @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');
     }
 }
Пример #4
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()));
     }
 }
Пример #5
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');
 }
Пример #6
0
 /**
  * @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');
     }
     if (!$input->getValue() instanceof \DateTime) {
         $input->replace(function ($value) {
             return new \DateTime($value);
         });
     }
 }
 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());
 }
 /**
  * @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));
     }
 }
Пример #9
0
 /**
  * @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));
     }
 }
Пример #10
0
 /**
  * @param InputValue $input
  * @param $key
  * @param AbstractSchema $schema
  * @throws ValidationException
  */
 private function processKey(InputValue $input, $key, AbstractSchema $schema)
 {
     if (!array_key_exists($key, $input->getValue())) {
         $this->handleMissingKey($input, $key, $schema->getOption('default'));
     } else {
         $this->validateAndReplaceKey($input, $key, $schema);
     }
 }
Пример #11
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);
     }
 }
Пример #12
0
 /**
  * @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));
     }
 }
 /**
  * @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);
     });
 }
 /**
  * @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);
     }
 }
Пример #15
0
 /**
  * @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);
     }
 }
Пример #16
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_bool($input->getValue())) {
         throw new ValidationException('value is not a boolean');
     }
 }
Пример #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');
     }
 }
Пример #18
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_resource($input->getValue())) {
         throw new ValidationException('value is not a resource');
     }
 }
Пример #19
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_array($input->getValue())) {
         throw new ValidationException('value is not an array');
     }
 }
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!ctype_alnum($input->getValue())) {
         throw new ValidationException('value contains not alphanumeric chars');
     }
 }
Пример #21
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_string($input->getValue())) {
         throw new ValidationException('value is not a string');
     }
 }
Пример #22
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()));
     }
 }
Пример #23
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()));
     }
 }
Пример #24
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (count($input->getValue()) === 0) {
         throw new ValidationException('value is an empty array');
     }
 }
Пример #25
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if ($input->getValue() !== false) {
         throw new ValidationException('value is not FALSE');
     }
 }
Пример #26
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');
     }
 }
Пример #27
0
 /**
  * @param InputValue $input
  * @throws ValidationException
  */
 public function process(InputValue $input)
 {
     if (!is_callable($input->getValue())) {
         throw new ValidationException('value is not callable');
     }
 }