mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Updated README.md
This commit is contained in:
parent
74a882969e
commit
ebbeca46af
23
README.md
23
README.md
@ -188,6 +188,29 @@ Valitron\Validator::addRule('alwaysFail', function($field, $value, array $params
|
||||
}, 'Everything you do is wrong. You fail.');
|
||||
```
|
||||
|
||||
You can also use one-off rules that are only valid for the specified
|
||||
fields.
|
||||
|
||||
```php
|
||||
$v = new Valitron\Validator(array("foo" => "bar"));
|
||||
$v->rule(function($field, $value, $params, $fields) {
|
||||
return true;
|
||||
}, "foo")->message("{field} failed...");
|
||||
```
|
||||
|
||||
This is useful because such rules can have access to variables
|
||||
defined in the scope where the `Validator` lives. The Closure's
|
||||
signature is identical to `Validator::addRule` callback's
|
||||
signature.
|
||||
|
||||
If you wish to add your own rules that are not static (i.e.,
|
||||
your rule is not static and available to call `Validator`
|
||||
instances), you need to use `Validator::addInstanceRule`.
|
||||
This rule will take the same parameters as
|
||||
`Validator::addRule` but it has to be called on a `Validator`
|
||||
instance.
|
||||
|
||||
|
||||
## Alternate syntax for adding rules
|
||||
|
||||
As the number of rules grows, you may prefer the alternate syntax
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user