-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace "LazyConsecutive" with "Consecutive"
With this and the Lazy rule, the LazyConsecutive lost its purpose. While working on it, I did refactor the Domain rule a bit, but mainly to check how this rule could behave. Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
78715fb
commit 2610a38
Showing
21 changed files
with
309 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Consecutive | ||
|
||
- `Consecutive(Validatable $rule1, Validatable $rule2, Validatable ...$rule)` | ||
|
||
Validates the input against a series of rules until one fails. | ||
|
||
This rule can be handy for getting the least error messages possible from a chain. | ||
|
||
This rule can be helpful in combinations with [Lazy](Lazy.md). An excellent example is when you want to validate a | ||
country code and a subdivision code. | ||
|
||
```php | ||
v::consecutive( | ||
v::key('countryCode', v::countryCode()), | ||
v::lazy(static fn($input) => v::key('subdivisionCode', v::subdivisionCode($input['countryCode']))), | ||
)->validate($_POST); | ||
``` | ||
|
||
You need a valid country code to create a [SubdivisionCode](SubdivisionCode.md), so it makes sense only to validate the | ||
subdivision code only if the country code is valid. In this case, you could also have used [When](When.md), but you | ||
would then have to write `v::key('countryCode', v::countryCode())` twice in your chain. | ||
|
||
## Categorization | ||
|
||
- Composite | ||
- Conditions | ||
- Nesting | ||
|
||
## Changelog | ||
|
||
| Version | Description | | ||
|--------:|-------------| | ||
| 3.0.0 | Created | | ||
|
||
*** | ||
See also: | ||
|
||
- [AllOf](AllOf.md) | ||
- [AnyOf](AnyOf.md) | ||
- [Lazy](Lazy.md) | ||
- [NoneOf](NoneOf.md) | ||
- [OneOf](OneOf.md) | ||
- [SubdivisionCode](SubdivisionCode.md) | ||
- [When](When.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ See also: | |
|
||
- [Call](Call.md) | ||
- [CallableType](CallableType.md) | ||
- [Consecutive](Consecutive.md) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Respect\Validation\Rules; | ||
|
||
use Respect\Validation\Helpers\CanBindEvaluateRule; | ||
use Respect\Validation\Result; | ||
use Respect\Validation\Rules\Core\Composite; | ||
|
||
final class Consecutive extends Composite | ||
{ | ||
use CanBindEvaluateRule; | ||
|
||
public function evaluate(mixed $input): Result | ||
{ | ||
foreach ($this->rules as $rule) { | ||
$result = $this->bindEvaluate($rule, $this, $input); | ||
if (!$result->isValid) { | ||
return $result; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.