mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
This commit introduces REUSE compliance by annotating all files with SPDX information and placing the reused licences in the LICENSES folder. We additionally removed the docheader tool which is made obsolete by this change. The main LICENSE and copyright text of the project is now not under my personal name anymore, and it belongs to "The Respect Project Contributors" instead. This change restores author names to several files, giving the appropriate attribution for contributions.
2.1 KiB
2.1 KiB
Call
Call(callable $callable, Validator $validator)
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::notBlank());
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::notBlank())
)->assert($url);
// Validation passes successfully
Templates
Call::TEMPLATE_STANDARD
| Mode | Template |
|---|---|
default |
{{input}} must be a suitable argument for {{callable}} |
inverted |
{{input}} must not be a suitable argument for {{callable}} |
Template placeholders
| Placeholder | Description |
|---|---|
callable |
|
input |
|
subject |
The validated input or the custom validator name (if specified). |
Categorization
- Callables
- Nesting
- Transformations
Changelog
| Version | Description |
|---|---|
| 0.3.9 | Created |
See also: