Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Added Explode validator documentation #209

Merged
merged 2 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions doc/book/validators/explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Explode Validator

`Zend\Validator\Explode` executes a validator for each item exploded.

## Supported options

The following options are supported for `Zend\Validator\Explode`:

- `valueDelimiter`: Defines the delimiter used to explode the value to an array. It defaults to `,`. If working with an array, this option isn't used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@renanliberato

If working with an array, this option isn't used.

We should clarify that the given "value" is meant here.

- `validator`: Sets the validator that will be executed on each exploded item.

## Basic usage

To validate if every item in an array is into a certain haystack:

```php
$inArrayValidator = new Zend\Validator\InArray([
'haystack' => [1, 2, 3, 4, 5, 6]
]);

$explodeValidator = new Zend\Validator\Explode([
'validator' => $inArrayValidator
]);

$value = [1, 4, 6, 8];
$return = $valid->isValid($value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$valid is wrong here.

I would change the example:

$explodeValidator->isValid([1, 4, 6]);    // returns true
$explodeValidator->isValid([1, 4, 6, 8]); // returns false

// returns false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be deleted.

```

The above example returns `true` if all $value items are between 1 and 6.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be deleted, because is covered now in the example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add another example which demonstrate the usage of valueDelimiter. Thanks!

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pages:
- "Db\\RecordExists and Db\\NoRecordExists": validators/db.md
- Digits: validators/digits.md
- EmailAddress: validators/email-address.md
- Explode: validators/explode.md
- GreaterThan: validators/greater-than.md
- Hex: validators/hex.md
- Hostname: validators/hostname.md
Expand Down