-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Labels
Description
Currently, ExecutionContextInterface::addViolation() has a lot of optional parameters:
public function addViolation($message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null);
public function addViolationAt($subPath, $message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null);After #6129, we need to add another parameter $translationDomain to that list. Instead of adding a new parameter, I propose to deprecate all parameters after $params and introduce a new method getViolationBuilder() so that we end up with the following API in 2.3 (when deprecation is over):
public function addViolation($message, array $params = array());
public function addViolationAt($subPath, $message, array $params = array());
public function getViolationBuilder($message);
public function getViolationBuilderAt($subPath, $message);and used like this:
// simple violations remain the same
$context->addViolationAt('foo', 'Foo is invalid!');
// complex violations will be easier to read and write
$context->getViolationBuilderAt('foo', 'The value {{ foo }} is invalid!')
->setParam('{{ foo }}', 'bar')
->setTranslationDomain('validators/foo')
->setInvalidValue('bar')
->addViolation();Depends on #6137 to be merged.