mirror of
https://github.com/Respect/Validation.git
synced 2024-06-26 17:20:16 +02:00
238f2d506a
There are a few "problems" with the current engine: - Allowing each rule to execute assert() and check() means duplication in some cases. - Because we use exceptions to assert/check, we can only invert a validation (with Not) if there are errors. That means that we have limited granularity control. - There is a lot of logic in the exceptions. That means that even after it throws an exception, something could still happen. We're stable on that front, but I want to simplify them. Besides, debugging exception code is painful because the stack trace does not go beyond the exception. Apart from that, there are many limitations with templating, and working that out in the current implementation makes it much harder. These changes will improve the library in many aspects, but they will also change the behavior and break backward compatibility. However, that's a price I'm willing to pay for the improvements we'll have. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
24 lines
755 B
PHP
24 lines
755 B
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
exceptionMessage(static fn() => v::noneOf(v::intType(), v::positive())->check(42));
|
|
exceptionMessage(static fn() => v::not(v::noneOf(v::intType(), v::positive()))->check('-1'));
|
|
exceptionFullMessage(static fn() => v::noneOf(v::intType(), v::positive())->assert(42));
|
|
exceptionFullMessage(static fn() => v::not(v::noneOf(v::intType(), v::positive()))->assert('-1'));
|
|
?>
|
|
--EXPECT--
|
|
42 must not be of type integer
|
|
"-1" must be of type integer
|
|
- None of these rules must pass for 42
|
|
- 42 must not be of type integer
|
|
- 42 must not be positive
|
|
- All of these rules must pass for "-1"
|
|
- "-1" must be of type integer
|
|
- "-1" must be positive
|