Ok, I found the cause of my problem.
Validator itself uses GraphWalker, which intializes all the validators
before each field validation. This works fine.
But somwhere else I used Validation as $validator = new MyValidator();
$validator->isValid($value, new MyContraint());
And this failed because after update it's now needed to add
$validator->initialize($context); after instantiating new validator object.
So my problem is fixed.
But the question arises: Is there any valid way to validate some data
against existing contraints without using the validator (to have less
dependencies).
My assumption is to have a third parameter in validator - a boolean value
(defaults to true) which is checked for adding violations.
So the simple example is:
$validator = new MyValidator(); $validator->isValid($value, null, false);
inside isValid:
public function isValid($value, Constraint $constraint = null,
$addViolation = true)
{
if (!is_numeric($value)) {
if ($addViolation) {
$this->context->addViolation(
$constraint->message,
array('{{ value }}' => $value)
);
}
return false;
}
return true;
}
So that if simply used to just check if something is valid - it just
returns boolean false on invalid value and true on valid value. And in this
case it can be used without any other dependency being involved. Even
constraint is not required (which in this case is logically truth)
What do you think?
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en