respect-validation/docs/rules/Call.md
Henrique Moody 061a3c9c09
Rename method "validate()" to "isValid()"
The method has been renamed some time ago, but I haven't updated the
documentation to cause less confusion. Now that I want to start updating
the documentation, I switched the default branch on GitHub to the latest
stable version, so I assume there will be less confusion in the
documentation, and I can start updating the docs for the next version.
2024-12-02 22:11:57 +01:00

1.1 KiB

Call

  • Call(callable $callable, Rule $rule)

Validates the return of a [callable][] for a given input.

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())
)->isValid($url);

Categorization

  • Callables
  • Nesting
  • Transformations

Changelog

Version Description
0.3.9 Created

See also: