emonkak / validation
A type-based validation library
Installs: 2 484
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-10-29 04:17:37 UTC
README
Example
use Emonkak\Validation\Types; use Emonkak\Validation\Validator; $validator = new Validator([ 'foo' => Types::oneOfType([Types::int(), Types::bool()]), 'bar' => Types::string(), 'baz' => Types::bool(), 'qux' => Types::any(), 'quux' => Types::arrayOf(Types::string()), 'foobar' => Types::string()->isOptional(), 'piyo' => Types::oneOf(['foo', 'bar']), 'puyo' => Types::shape('Puyo', ['foo' => Types::string()]), 'payo' => Types::dateTime(), ]); $errors = $validator->validate([ 'foo' => 'foo', 'bar' => '123', 'baz' => 'true', 'qux' => null, 'quux' => ['1', '2'], 'puyo' => ['foo' => 123], 'payo' => '2000-01-01 00:00:00' ]); foreach ($errors->getErrors() as $key => $errors) { echo $key, ': ', implode(' ', $errors), PHP_EOL; } // OUTPUT: // foo: The property `foo` must be `integer|boolean`, got `string`. // qux: The property `qux` must be `any`, got `NULL`. // piyo: The property `piyo` must be `"foo"|"bar"`, got `NULL`. // puyo.foo: The property `puyo.foo` must be `string`, got `integer`.
Licence
MIT Licence