/** * @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) { 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) { $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) { if ($input->getValue() instanceof \DateTime) { return; } if (is_string($input->getValue()) && false !== strtotime($input->getValue())) { return; } throw new ValidationException('value is not a date'); }
/** * @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)); } }
/** * @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 * @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); } }
/** * @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) { $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); } }
/** * @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) { if (!is_bool($input->getValue())) { throw new ValidationException('value is not a boolean'); } }
/** * @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 (!is_resource($input->getValue())) { throw new ValidationException('value is not a resource'); } }
/** * @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'); } }
/** * @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 (!in_array($input->getValue(), $this->getOption('allowed'))) { throw new ValidationException(sprintf('value "%s" is not allowed', $input->getValue())); } }
/** * @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 (count($input->getValue()) === 0) { throw new ValidationException('value is an empty array'); } }
/** * @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 (!is_integer($input->getValue()) && !is_float($input->getValue())) { throw new ValidationException('value is not a number'); } }
/** * @param InputValue $input * @throws ValidationException */ public function process(InputValue $input) { if (!is_callable($input->getValue())) { throw new ValidationException('value is not callable'); } }