mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 00:32:16 +02:00
52614d600d
The current documentation is hosted via GitHub pages rendered by "Couscous". Every time we need a new version of the documentation published we need to manually execute the "couscous". This commit reorganize the documentation to be published to "Read the Docs" because it will also allow us to have documentations per version of the library most importantly provider a search field for the documentation. The documentation will be then published on: https://respect-validation.readthedocs.io/ Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
1.2 KiB
1.2 KiB
Call
v::call(callable $callback)
This is a very low level validator. It calls a function, method or closure for the input and then validates it. Consider the following variable:
$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:
$parts = parse_url($url);
This function returns an array containing scheme
, host
, path
and query
.
We can validate them this way:
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:
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);
It is possible to call methods and closures as the first parameter:
v::call([$myObj, 'methodName'], v::intVal())->validate($myInput);
v::call(function($input) {}, v::intVal())->validate($myInput);
See also: