/** * @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())); } }
/** * @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) { 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 ($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); }); }
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) { 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 */ public function process(InputValue $input) { $input->replace(function ($value) { return str_replace($this->getOption('search'), $this->getOption('replace'), $value); }); }
/** * @param InputValue $input */ public function process(InputValue $input) { $input->replace(function ($value) { return preg_replace($this->getOption('pattern'), $this->getOption('replace'), $value); }); }
/** * @param InputValue $input */ public function toUpper(InputValue $input) { $input->replace(function ($value) { return strtoupper($value); }); }