-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
validator: comparison constraints value #10863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
<value>x</value> throws a ConstraintDefinitionException in Symfony\Component\Validator\Constraints
Can you show the full error and stack trace that you got without these changes? |
Tried it in 2 completely different projects (sf 3.4 and 4.2) with both the same result
namespace App;
class Test
{
public $test = 10;
} class Service
{
private $validator;
public function __construct(
ValidatorInterface $validator
) {
$this->validator = $validator;
}
public function xxx()
{
$test = new Test();
$errors = $this->validator->validate($test);
}
}
If I dump the $options in AbstractComparison the result is
|
Could be a regression that should be fixed in the core instead. I can have a look at it this week-end. WDYT @xabbuh? |
@HeahDude Reading the code again this seems to be intended. What should also work is this: <?xml version="1.0" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="App\Test">
<property name="test">
<constraint name="EqualTo">
<value key="value">5</value>
</constraint>
</property>
</class>
</constraint-mapping> But for this example I think that would be more confusing than the proposed change. |
@wimme002 thanks for fixing this error! |
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #10863). Discussion ---------- validator: comparison constraints value When the comparison constraints have 1 or more <value> nodes, a ConstraintDefinitionException error is thrown in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/AbstractComparison.php because the keys of the array in the constructor do not have a value Commits ------- c318f85 validator: comparison constraints value
When the comparison constraints have 1 or more nodes, a ConstraintDefinitionException error is thrown in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/AbstractComparison.php because the keys of the array in the constructor do not have a value