mirror of
https://github.com/Respect/Validation.git
synced 2026-03-14 22:35:45 +01:00
Improves SPDX header linting to ensure consistent license metadata across the codebase. Key changes: - Enforce deterministic tag ordering (License-Identifier, FileCopyrightText, FileContributor) to ensure consistency, prevent merge conflicts, and simplify code reviews - Add contributor alias mapping to consolidate contributors with multiple emails or name variations (e.g., "nickl-" → "Nick Lombard") - Add --contributions-strategy option with "blame" (current code authors) and "log" (all historical contributors) to support different attribution philosophies - Add optional path argument to lint specific files or directories - Add --fix option to automatically correct header issues Assisted-by: Claude Code (claude-opus-4-5-20251101)
2.2 KiB
2.2 KiB
After
After(callable $callable, Validator $validator)
Validates the input after applying a [callable][] to it.
v::after(str_split(...), v::arrayType()->lengthEquals(5))->assert('world');
// Validation passes successfully
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::after(
'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
After does not handle possible errors (type mismatches). If you need to
ensure that your callback is of a certain type, use Circuit or
handle it using a closure:
v::after('strtolower', v::equals('ABC'))->assert(123);
// 𝙭 strtolower(): Argument #1 ($string) must be of type string, int given
v::circuit(v::stringType(), v::after('strtolower', v::equals('abc')))->assert(123);
// → 123 must be a string
v::circuit(v::stringType(), v::after('strtolower', v::equals('abc')))->assert('ABC');
// Validation passes successfully
Categorization
- Callables
- Nesting
- Transformations
Changelog
| Version | Description |
|---|---|
| 3.0.0 | No longer sets error handlers and got renamed to After |
| 2.0.0 | Sets error handlers |
| 0.3.9 | Created as Call |