From ebbeca46af510934dcb9c68840865b1d558b8437 Mon Sep 17 00:00:00 2001 From: Matteo Kloiber Date: Sun, 6 Nov 2016 01:46:34 +0100 Subject: [PATCH] Updated README.md --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index c2f7195..18ee53c 100644 --- a/README.md +++ b/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