diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index 031bf420ce530..8cc289bb6b819 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -37,18 +37,10 @@ class ExpressionValidator extends ConstraintValidator */ private $expressionLanguage; - /** - * @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5 - * - * @throws UnexpectedTypeException If the property accessor is invalid - */ - public function __construct($propertyAccessor = null) + public function __construct(PropertyAccessorInterface $propertyAccessor = null, ExpressionLanguage $expressionLanguage = null) { - if (null !== $propertyAccessor && !$propertyAccessor instanceof PropertyAccessorInterface) { - throw new UnexpectedTypeException($propertyAccessor, 'null or \Symfony\Component\PropertyAccess\PropertyAccessorInterface'); - } - $this->propertyAccessor = $propertyAccessor; + $this->expressionLanguage = $expressionLanguage; } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index 62cbdbf02f673..61510abc37e56 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -217,4 +217,28 @@ public function testFailingExpressionAtPropertyLevelWithoutRoot() ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } + + public function testExpressionLanguageUsage() + { + $constraint = new Expression(array( + 'expression' => 'false', + )); + + $expressionLanguage = $this->getMock('Symfony\Component\ExpressionLanguage\ExpressionLanguage'); + + $used = false; + + $expressionLanguage->method('evaluate') + ->will($this->returnCallback(function () use (&$used) { + $used = true; + + return true; + })); + + $validator = new ExpressionValidator(null, $expressionLanguage); + $validator->initialize($this->createContext()); + $validator->validate(null, $constraint); + + $this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.'); + } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: