-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update NullOr to generate results with siblings
Since I updated the validation engine[1], it became possible to create results with siblings. This commit changes the "NullOr", allowing it to create a result with a sibling when possible. That will improve the clarity of the error message. I also updated the documentation, since it was still called "Nullable" [1]: 238f2d5
- Loading branch information
1 parent
061a3c9
commit d1e0c8b
Showing
10 changed files
with
185 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# NullOr | ||
|
||
- `NullOr(Validatable $rule)` | ||
|
||
Validates the input using a defined rule when the input is not `null`. | ||
|
||
## Usage | ||
|
||
```php | ||
v::nullable(v::email())->isValid(null); // true | ||
v::nullable(v::email())->isValid('[email protected]'); // true | ||
v::nullable(v::email())->isValid('not an email'); // false | ||
``` | ||
|
||
## Prefix | ||
|
||
For convenience, you can use `nullOr` as a prefix to any rule: | ||
|
||
```php | ||
v::nullOrEmail()->isValid('not an email'); // false | ||
v::nullOrBetween(1, 3)->isValid(2); // true | ||
v::nullOrBetween(1, 3)->isValid(null); // true | ||
``` | ||
|
||
## Templates | ||
|
||
| Id | Default | Inverted | | ||
|-----------------------------|-----------------|----------------------| | ||
| `NullOr::TEMPLATE_STANDARD` | or must be null | and must not be null | | ||
|
||
The templates from this rule serve as message suffixes: | ||
|
||
```php | ||
v::nullOr(v::alpha())->assert('has1number'); | ||
// "has1number" must contain only letters (a-z) or must be null | ||
|
||
v::not(v::nullOr(v::alpha()))->assert("alpha"); | ||
// "alpha" must not contain letters (a-z) and must not be null | ||
``` | ||
|
||
## Template placeholders | ||
|
||
| Placeholder | Description | | ||
|-------------|------------------------------------------------------------------| | ||
| `name` | The validated input or the custom validator name (if specified). | | ||
|
||
## Categorization | ||
|
||
- Nesting | ||
|
||
## Changelog | ||
|
||
| Version | Description | | ||
|--------:|-----------------------| | ||
| 3.0.0 | Renamed to `NullOr` | | ||
| 2.0.0 | Created as `Nullable` | | ||
|
||
*** | ||
See also: | ||
|
||
- [NullType](NullType.md) | ||
- [UndefOr](UndefOr.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 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
Oops, something went wrong.