You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to create another rule for reuse logic instead coding same logic in callbacks approach. I made success coding simple logics (using the manual to extending Particle), but when I've tried to create one rule named greaterThanDate($param), where $param is the name of field that I suppose do compare it. It not works.
What is expected
<?phpnamespaceB4\Validators\Rules;
useParticle\Validator\Rule;
classGreaterThanDateextendsRule
{
constNOT_GREATER = 'CpfRule::NOT_GREATER';
protected$messageTemplates = [
self::NOT_GREATER => 'Data {{ name }} não é maior que data {{ field }}.',
];
private$dateField;
publicfunction__construct($dateField) {
$this->dateField = $dateField;
}
publicfunctionvalidate($value) {
if ($value > $this->values[$this->dateField]) {
returntrue;
}
return$this->error(self::NOT_GREATER);
}
protectedfunctiongetMessageParameters()
{
return array_merge(parent::getMessageParameters(), [
'field' => $this->dateField,
]);
}
}
As you can see $this->values[$this->dateField] should be the file accessed to obtain this information, but $this->values seems to be null. In Rule class, has a protected attribute named $values that should store this information. Am I right?
The text was updated successfully, but these errors were encountered:
Hello @rsandimbefore, sorry for the late reply, I lost track of this issue.
To answer your question, on the abstract Rule class, there is an attribute $values, but when I check the code, only in the Rule\Callback class that value is actually filled (here). We could change that for all classes by filling the $values attribute here. That explains why your $values attribute was null in your custom rule.
I hope this answered your question, and I hope the answer is not too late. If you have any more questions feel free to reply to this ticket or open a new one!
What I would create
Hi, I would like to create another rule for reuse logic instead coding same logic in callbacks approach. I made success coding simple logics (using the manual to extending Particle), but when I've tried to create one rule named greaterThanDate($param), where $param is the name of field that I suppose do compare it. It not works.
What is expected
As you can see $this->values[$this->dateField] should be the file accessed to obtain this information, but $this->values seems to be null. In Rule class, has a protected attribute named $values that should store this information. Am I right?
The text was updated successfully, but these errors were encountered: