respect-validation/docs/rules/Call.md
Henrique Moody 10df3211f5
Add "Categorization" section to rule documentations
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-11 19:16:21 +02:00

60 lines
1.1 KiB
Markdown

# Call
- `Call(callable $callable, Rule $rule)`
Validates the return of a [callable][] for a given input.
Consider the following variable:
```php
$url = 'http://www.google.com/search?q=respect.github.com';
```
To validate every part of this URL we could use the native `parse_url`
function to break its parts:
```php
$parts = parse_url($url);
```
This function returns an array containing `scheme`, `host`, `path` and `query`.
We can validate them this way:
```php
v::arrayVal()
->key('scheme', v::startsWith('http'))
->key('host', v::domain())
->key('path', v::stringType())
->key('query', v::notEmpty());
```
Using `v::call()` you can do this in a single chain:
```php
v::call(
'parse_url',
v::arrayVal()->key('scheme', v::startsWith('http'))
->key('host', v::domain())
->key('path', v::stringType())
->key('query', v::notEmpty())
)->validate($url);
```
## Categorization
- Callables
- Nesting
## Changelog
Version | Description
--------|-------------
0.3.9 | Created
***
See also:
- [Callback](Callback.md)
- [Each](Each.md)
- [Sorted](Sorted.md)