mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 23:02:16 +02:00
97b243daa1
Although helpful, the changes in the Min, Max, and Length rules made using those rules more verbose. This commit will simplify their use by allowing users to use them as prefixes. Because I was creating prefixes for those rules, I made other cool prefixes. Doing that is scary because it will generate more code to support, and I would have liked to avoid that. However, that's a valuable addition, and it's worth the risk. I might reconsider that in the future, but for now, that looks like a good idea. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
27 lines
778 B
PHP
27 lines
778 B
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
exceptionFullMessage(static function (): void {
|
|
v::property('title', v::lengthBetween(2, 3)->stringType())
|
|
->property('description', v::stringType())
|
|
->property('author', v::intType()->lengthBetween(1, 2))
|
|
->property('user', v::intVal()->lengthBetween(1, 2))
|
|
->assert((object) ['author' => 'foo']);
|
|
});
|
|
|
|
?>
|
|
--EXPECT--
|
|
- All of the required rules must pass for `stdClass { +$author="foo" }`
|
|
- title must be present
|
|
- description must be present
|
|
- All of the required rules must pass for author
|
|
- author must be of type integer
|
|
- The length of author must be between 1 and 2
|
|
- user must be present
|