mirror of
https://github.com/Respect/Validation.git
synced 2024-06-26 17:20:16 +02:00
980ab28707
When we created this rule in version 1.0 in 2015, PHP was in version 5.6, and the `is_iterable()` function didn't exist. Only in version 7.1, released at the end of 2016, was the pseudo-type "iterable" introduced to PHP. This old "IterableType" rule is almost obsolete. Still, I decided to keep it because it is possible to use foreach in any object, as it will iterate over its public properties. I did rename the rule because that makes more sense. An "IterableType" rule should guarantee that the input type is the real-(pseudo)-iterable. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
20 lines
537 B
PHP
20 lines
537 B
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
exceptionMessage(static fn() => v::iterableVal()->check(3));
|
|
exceptionMessage(static fn() => v::not(v::iterableVal())->check([2, 3]));
|
|
exceptionFullMessage(static fn() => v::iterableVal()->assert('String'));
|
|
exceptionFullMessage(static fn() => v::not(v::iterableVal())->assert(new stdClass()));
|
|
?>
|
|
--EXPECT--
|
|
3 must be iterable
|
|
`[2, 3]` must not be iterable
|
|
- "String" must be iterable
|
|
- `stdClass {}` must not be iterable
|