mirror of
https://github.com/Respect/Validation.git
synced 2024-06-13 19:22: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>
51 lines
2.3 KiB
PHP
51 lines
2.3 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
$input = [
|
|
'foo' => (object) [
|
|
'bar' => 123,
|
|
],
|
|
];
|
|
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar.baz')->assert(['foo.bar.baz' => false]));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar')->assert($input));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar')->assert(new ArrayObject($input)));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar', v::negative())->assert($input));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar')->assert($input));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar', v::stringType())->assert($input));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar.baz', v::notEmpty(), false)->assert($input));
|
|
exceptionMessage(static fn() => v::keyNested('foo.bar', v::floatType(), false)->assert($input));
|
|
// phpcs:disable Generic.Files.LineLength.TooLong
|
|
?>
|
|
--EXPECTF--
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
foo must be present after asserting that `["foo.bar.baz": false]` must be an array value
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
No exception was thrown
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
No exception was thrown
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
bar must be negative
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
No exception was thrown
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
bar must be of type string
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
No exception was thrown
|
|
|
|
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
|
|
bar must be of type float
|