-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the "UndefOr" rule and related classes
This commit will rename the "Optional" rule to"UndefOr" while soft deprecating the old name. It should work the same as the previous one but with a different name. It will also prefix the result ID, allowing more message customization. While working on it, I realized that the prefix "undefOr" had a typo, and it was using "undefOf" instead. I fixed that, too. Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
eeaea46
commit 707dcae
Showing
24 changed files
with
677 additions
and
481 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# UndefOr | ||
|
||
- `UndefOr(Validatable $rule)` | ||
|
||
Validates if the given input is undefined or not. | ||
|
||
By _undefined_ we consider `null` or an empty string (`''`), which implies that the input is not set. This is particularly useful when validating form fields | ||
|
||
```php | ||
v::undefOr(v::alpha())->validate(''); // true | ||
v::undefOr(v::digit())->validate(null); // true | ||
|
||
v::undefOr(v::alpha())->validate('username'); // true | ||
v::undefOr(v::alpha())->validate('has1number'); // false | ||
``` | ||
|
||
## Note | ||
|
||
For convenience, you can use the `undefOr` as a prefix to any rule: | ||
|
||
```php | ||
v::undefOrEmail()->validate('not an email'); // false | ||
v::undefOrBetween(1, 3)->validate(2); // true | ||
``` | ||
|
||
## Categorization | ||
|
||
- Nesting | ||
|
||
## Changelog | ||
|
||
| Version | Description | | ||
|--------:|--------------------------------------| | ||
| 3.0.0 | Renamed from "Optional" to "UndefOr" | | ||
| 1.0.0 | Created | | ||
|
||
*** | ||
See also: | ||
|
||
- [NoWhitespace](NoWhitespace.md) | ||
- [NotBlank](NotBlank.md) | ||
- [NotEmpty](NotEmpty.md) | ||
- [NotOptional](NotOptional.md) | ||
- [NullType](NullType.md) | ||
- [Nullable](Nullable.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
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.