mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 02:30:06 +02:00
Merge branch '1.1'
This commit is contained in:
commit
89c82b2fa2
|
@ -6,7 +6,8 @@ language:
|
|||
|
||||
php:
|
||||
- 5.6
|
||||
- 7
|
||||
- 7.0
|
||||
- 7.1
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
|
|
|
@ -19,7 +19,7 @@ See also:
|
|||
* [Countable](Countable.md)
|
||||
* [FloatType](FloatType.md)
|
||||
* [IntType](IntType.md)
|
||||
* [Iterable](Iterable.md)
|
||||
* [IterableType](IterableType.md)
|
||||
* [NullType](NullType.md)
|
||||
* [ObjectType](ObjectType.md)
|
||||
* [ResourceType](ResourceType.md)
|
||||
|
|
|
@ -16,7 +16,7 @@ See also:
|
|||
* [ArrayType](ArrayType.md)
|
||||
* [Countable](Countable.md)
|
||||
* [Each](Each.md)
|
||||
* [Iterable](Iterable.md)
|
||||
* [IterableType](IterableType.md)
|
||||
* [Key](Key.md)
|
||||
* [KeySet](KeySet.md)
|
||||
* [KeyValue](KeyValue.md)
|
||||
|
|
|
@ -16,4 +16,4 @@ See also:
|
|||
|
||||
* [ArrayVal](ArrayVal.md)
|
||||
* [Instance](Instance.md)
|
||||
* [Iterable](Iterable.md)
|
||||
* [IterableType](IterableType.md)
|
||||
|
|
|
@ -2,19 +2,4 @@
|
|||
|
||||
- `v::iterable()`
|
||||
|
||||
Validates if the input is iterable, in other words, if you're able to iterate
|
||||
over it with [foreach](http://php.net/foreach) language construct.
|
||||
|
||||
```php
|
||||
v::iterable()->validate([]); // true
|
||||
v::iterable()->validate(new ArrayObject()); // true
|
||||
v::iterable()->validate(new stdClass()); // true
|
||||
v::iterable()->validate('string'); // false
|
||||
```
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
* [ArrayVal](ArrayVal.md)
|
||||
* [Countable](Countable.md)
|
||||
* [Instance](Instance.md)
|
||||
**Deprecated**: Use [IterableType](IterableType.md) instead.
|
||||
|
|
20
docs/IterableType.md
Normal file
20
docs/IterableType.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# IterableType
|
||||
|
||||
- `v::iterableType()`
|
||||
|
||||
Validates if the input is iterable, in other words, if you're able to iterate
|
||||
over it with [foreach](http://php.net/foreach) language construct.
|
||||
|
||||
```php
|
||||
v::iterableType()->validate([]); // true
|
||||
v::iterableType()->validate(new ArrayObject()); // true
|
||||
v::iterableType()->validate(new stdClass()); // true
|
||||
v::iterableType()->validate('string'); // false
|
||||
```
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
* [ArrayVal](ArrayVal.md)
|
||||
* [Countable](Countable.md)
|
||||
* [Instance](Instance.md)
|
|
@ -15,7 +15,7 @@
|
|||
* [Instance](Instance.md)
|
||||
* [IntVal](IntVal.md)
|
||||
* [IntType](IntType.md)
|
||||
* [Iterable](Iterable.md)
|
||||
* [IterableType](IterableType.md)
|
||||
* [NullType](NullType.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [ObjectType](ObjectType.md)
|
||||
|
@ -259,7 +259,7 @@
|
|||
* [IntVal](IntVal.md)
|
||||
* [IntType](IntType.md)
|
||||
* [Ip](Ip.md)
|
||||
* [Iterable](Iterable.md)
|
||||
* [IterableType](IterableType.md)
|
||||
* [Json](Json.md)
|
||||
* [Key](Key.md)
|
||||
* [KeyNested](KeyNested.md)
|
||||
|
|
|
@ -36,7 +36,7 @@ class IpException extends ValidationException
|
|||
if (isset($range['max'])) {
|
||||
$message .= '-'.$range['max'];
|
||||
} else {
|
||||
$message .= '/'.long2ip($range['mask']);
|
||||
$message .= '/'.long2ip((int) $range['mask']);
|
||||
}
|
||||
|
||||
$params['range'] = $message;
|
||||
|
|
|
@ -11,14 +11,5 @@
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class IterableException extends ValidationException
|
||||
{
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::STANDARD => '{{name}} must be iterable',
|
||||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::STANDARD => '{{name}} must not be iterable',
|
||||
],
|
||||
];
|
||||
}
|
||||
class IterableException extends IterableTypeException
|
||||
{}
|
||||
|
|
24
library/Exceptions/IterableTypeException.php
Normal file
24
library/Exceptions/IterableTypeException.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Respect/Validation.
|
||||
*
|
||||
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
*
|
||||
* For the full copyright and license information, please view the "LICENSE.md"
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class IterableTypeException extends ValidationException
|
||||
{
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::STANDARD => '{{name}} must be iterable',
|
||||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::STANDARD => '{{name}} must not be iterable',
|
||||
],
|
||||
];
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace Respect\Validation\Rules;
|
|||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Validatable;
|
||||
|
||||
class Each extends Iterable
|
||||
class Each extends IterableType
|
||||
{
|
||||
public $itemValidator;
|
||||
public $keyValidator;
|
||||
|
|
|
@ -9,14 +9,6 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Iterable extends AbstractRule
|
||||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return is_array($input) ||
|
||||
$input instanceof \stdClass ||
|
||||
$input instanceof \Traversable;
|
||||
}
|
||||
if (version_compare(PHP_VERSION, '7.1', '<')) {
|
||||
eval('namespace Respect\Validation\Rules; class Iterable extends IterableType {}');
|
||||
}
|
||||
|
|
22
library/Rules/IterableType.php
Normal file
22
library/Rules/IterableType.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Respect/Validation.
|
||||
*
|
||||
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
*
|
||||
* For the full copyright and license information, please view the "LICENSE.md"
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class IterableType extends AbstractRule
|
||||
{
|
||||
public function validate($input)
|
||||
{
|
||||
return is_array($input) ||
|
||||
$input instanceof \stdClass ||
|
||||
$input instanceof \Traversable;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ require 'vendor/autoload.php';
|
|||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
v::iterable()->assert([1, 2, 3]);
|
||||
v::iterable()->check(new ArrayObject());
|
||||
v::iterableType()->assert([1, 2, 3]);
|
||||
v::iterableType()->check(new ArrayObject());
|
||||
?>
|
||||
--EXPECTF--
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\IterableException;
|
||||
use Respect\Validation\Exceptions\IterableTypeException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::iterable()->check(3);
|
||||
} catch (IterableException $exception) {
|
||||
v::iterableType()->check(3);
|
||||
} catch (IterableTypeException $exception) {
|
||||
echo $exception->getMainMessage();
|
||||
}
|
||||
?>
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\IterableException;
|
||||
use Respect\Validation\Exceptions\IterableTypeException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::not(v::iterable())->check([2, 3]);
|
||||
} catch (IterableException $exception) {
|
||||
v::not(v::iterableType())->check([2, 3]);
|
||||
} catch (IterableTypeException $exception) {
|
||||
echo $exception->getMainMessage();
|
||||
}
|
||||
?>
|
|
@ -6,7 +6,7 @@ use Respect\Validation\Exceptions\AllOfException;
|
|||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::iterable()->assert('String');
|
||||
v::iterableType()->assert('String');
|
||||
} catch (AllOfException $exception) {
|
||||
echo $exception->getFullMessage();
|
||||
}
|
|
@ -6,7 +6,7 @@ use Respect\Validation\Exceptions\AllOfException;
|
|||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::not(v::iterable())->assert(new stdClass());
|
||||
v::not(v::iterableType())->assert(new stdClass());
|
||||
} catch (AllOfException $exception) {
|
||||
echo $exception->getFullMessage();
|
||||
}
|
|
@ -16,7 +16,7 @@ use ReflectionClass;
|
|||
|
||||
class CheckExceptionsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $deprecateds = [];
|
||||
protected $deprecateds = ['Iterable'];
|
||||
|
||||
public function provideListOfRuleNames()
|
||||
{
|
||||
|
|
|
@ -13,13 +13,13 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers Respect\Validation\Rules\Iterable
|
||||
* @covers Respect\Validation\Rules\IterableType
|
||||
*/
|
||||
class IterableTest extends RuleTestCase
|
||||
{
|
||||
public function providerForValidInput()
|
||||
{
|
||||
$rule = new Iterable();
|
||||
$rule = new IterableType();
|
||||
|
||||
return [
|
||||
[$rule, [1, 2, 3]],
|
||||
|
@ -30,7 +30,7 @@ class IterableTest extends RuleTestCase
|
|||
|
||||
public function providerForInvalidInput()
|
||||
{
|
||||
$rule = new Iterable();
|
||||
$rule = new IterableType();
|
||||
|
||||
return [
|
||||
[$rule, 3],
|
Loading…
Reference in a new issue