mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01:00
Because of how the validation engine works now [1], there's no reason to
keep adding names to each rule. Instead, create a single rule that
handles naming rules with a few other accessories. This change is not
necessarily simple, but it shrinks the `Rule` interface, and it's more
aligned with how the library works right now.
Personally, I think this API is much more straightforward than the
`setName()` method, as it's way more explicit about which rule we're
naming. Because of this change, the behaviour changed slightly, but it's
for the best.
Because of this change, I managed to remove a lot of code, but
unfortunately, it's quite a big-bang commit. It would be too complicated
to make it atomic since names are an intrinsic part of the library.
[1]: 238f2d506a
1.3 KiB
1.3 KiB
Templated
Templated(Rule $rule, string $template)Templated(Rule $rule, string $template, array<string, mixed> $parameters)
Defines a rule with a custom message template.
v::templated(v::email(), 'You must provide a valid email to signup')->assert('not an email');
// Message: You must provide a valid email to signup
v::templated(
v::notEmpty(),
'The author of the page {{title}} is empty, please fill it up.',
['title' => 'Feature Guide']
)->assert('');
// Message: The author of the page "Feature Guide" is empty, please fill it up.
This rule can be also useful when you're using Attributes and want a custom template for a specific property.
Templates
This rule does not have any templates, as you must define the templates yourself.
Template placeholders
| Placeholder | Description |
|---|---|
name |
The validated input or the custom validator name (if specified). |
Categorization
- Core
- Structures
- Miscellaneous
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Created |
See also: