respect-validation/docs/rules/Call.md

60 lines
1.1 KiB
Markdown
Raw Normal View History

2015-01-30 09:40:06 +01:00
# Call
- `Call(callable $callable, Rule $rule)`
2015-01-30 09:40:06 +01:00
Validates the return of a [callable][] for a given input.
Consider the following variable:
2015-01-30 09:40:06 +01:00
```php
$url = 'http://www.google.com/search?q=respect.github.com';
2015-01-30 09:40:06 +01:00
```
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());
2015-01-30 09:40:06 +01:00
```
Using `v::call()` you can do this in a single chain:
2015-01-30 09:40:06 +01:00
```php
v::call(
'parse_url',
2015-10-07 17:25:15 +02:00
v::arrayVal()->key('scheme', v::startsWith('http'))
2015-01-30 09:40:06 +01:00
->key('host', v::domain())
2015-10-07 16:52:03 +02:00
->key('path', v::stringType())
2015-01-30 09:40:06 +01:00
->key('query', v::notEmpty())
)->validate($url);
```
## Categorization
- Callables
- Nesting
## Changelog
Version | Description
--------|-------------
0.3.9 | Created
***
2015-01-30 09:40:06 +01:00
See also:
- [Callback](Callback.md)
2018-12-11 13:31:50 +01:00
- [Each](Each.md)
- [Sorted](Sorted.md)