This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/209' into develop
Forward port #209
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 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,48 @@ | ||
# Explode Validator | ||
|
||
`Zend\Validator\Explode` executes a validator for each item exploded from an | ||
array. | ||
|
||
## Supported options | ||
|
||
The following options are supported for `Zend\Validator\Explode`: | ||
|
||
- `valueDelimiter`: Defines the delimiter used to explode values from an array. | ||
It defaults to `,`. If the given value is an array, this option isn't used. | ||
- `validator`: Sets the validator that will be executed on each exploded item. | ||
This may be a validator instance, or a validator service name. | ||
|
||
## Basic usage | ||
|
||
To validate if every item in an array is in a specified haystack: | ||
|
||
```php | ||
$inArrayValidator = new Zend\Validator\InArray([ | ||
'haystack' => [1, 2, 3, 4, 5, 6], | ||
]); | ||
|
||
$explodeValidator = new Zend\Validator\Explode([ | ||
'validator' => $inArrayValidator | ||
]); | ||
|
||
$explodeValidator->isValid([1, 4, 6]); // returns true | ||
$explodeValidator->isValid([1, 4, 6, 8]); // returns false | ||
``` | ||
|
||
## Exploding strings | ||
|
||
To validate if every e-mail in a string is contained in a list of names: | ||
|
||
```php | ||
$inEmailListValidator = new Zend\Validator\InArray([ | ||
'haystack' => ['[email protected]', '[email protected]', '[email protected]'], | ||
]); | ||
|
||
$explodeValidator = new Zend\Validator\Explode([ | ||
'validator' => $inEmailListValidator, | ||
'valueDelimiter' => ',' | ||
]); | ||
|
||
$explodeValidator->isValid('[email protected],[email protected]'); // returns true | ||
$explodeValidator->isValid('[email protected],[email protected]'); // returns false | ||
``` |
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