if incoming data has an array value set with a slug rule on it, you get
preg_match() expects parameter 2 to be string, array given
vendor\vlucas\valitron\src\Valitron\Validator.php:571
Updates the credit card validator regular expression for the MasterCard brand to also match 16-digit card numbers starting with 22 - 27. Additionally, updates the unit test for credit cards with two published test cards in the new BIN range.
Additional information on the BIN range update can be found at: https://www.mastercard.us/en-us/issuers/get-support/2-series-bin-expansion.html
This has been achieved by making sure that the rule is neither
a "native" Validator rule (e.g. there is a validate{$CamleCaseName}
method) nor it has been registered.
If both conditions are met, the rule (even if it is a string)
will be accepted and used.
Tests for this case have also been added.
Validator::rule now allows the rule to be a closure.
This allows us to add an anonymous rule that is only
valid for the specified field(s):
$someObject = new MyObject();
$v->rule(function($field, $value) use ($someObject)
return $value === $someObject->someState();
}, ["shared_secret", "other"])
->label("invalid state!");
This is especially useful if you have either a) have
a rule which you are not likely to be reusing or b)
you need access to some object which cannot be easily
connstructed (because it requires IO access, etc).
Either way, this is really only convenience method
because it saves you a call to Validator::addInstanceRule.
Internally, it does exactly that: it 1) determines a valid
rule name, 2) calls addInstanceRule() with the name
determined in 1) and the Closure, and then 3) replaces
the $rule parameter (which is the Closure object) by
the name of the rule.
1) is determined like this: if multiple parameters were
given, they are joined together into one string glued
with a underscore. '_rule' is then appended so that
the name becomes all_params_rule. If the name is already
used by any other rule, it will append up to 5
pseudo-random digits to the rule. In the unlikely event
that this rule is also used, step 1) will be repeated
until a unique rule name is found.
Instance rules are not shared among other validator
objects (thus they are not static). This is useful
if you have a rule you do not want your other validators
to use (because it is very special to this validator).
The parameter given to addInstanceRule is identically to
addRule:
public function addInstanceRule(string $name, callable $callback [, string message])
Instead of appending to the static variables $_rules, and
$_ruleMessages, it now appends to $_instanceRules and
$_instanceRuleMessages.
A new getter for the rules and ruleMessage has also been added:
public array getRules()
public array getRuleMessages()
All existing code has been updated to use getRules(), and
getRuleMessages() instead of $_rules, and $_ruleMessages.