mirror of
https://github.com/Respect/Validation.git
synced 2024-06-28 02:00:06 +02:00
Currently, the Length rule does multiple things, yet it's limited. Because it does many things, it's also confusing. Turning the Length rule into a transformation allows for way more flexibility and clarity. The syntax becomes more verbose, but I can solve that later by creating a Transformer enables creating rules with the "length" as a prefix. While making this change, I also removed the support for counting objects and integers. I find that way too confusing. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
24 lines
623 B
PHP
24 lines
623 B
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator;
|
|
|
|
exceptionFullMessage(static function (): void {
|
|
Validator::create()
|
|
->key('username', Validator::length(Validator::between(2, 32)))
|
|
->key('birthdate', Validator::dateTime())
|
|
->setName('User Subscription Form')
|
|
->assert(['username' => '0', 'birthdate' => 'Whatever']);
|
|
});
|
|
?>
|
|
--EXPECT--
|
|
- All of the required rules must pass for User Subscription Form
|
|
- The length of username must be between 2 and 32
|
|
- birthdate must be a valid date/time
|