Skip to content

[Hackday][Validator] Add deprecated logs on addViolation() and addViolationAt() methods. #12714

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public function setConstraint(Constraint $constraint)
*/
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error(
'The parameters $invalidValue, $pluralization and $code are not supported anymore '.
'as of Symfony 2.5 and will be removed in Symfony 3.0. Please use buildViolation() instead.',
E_USER_DEPRECATED
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be triggered only if the user passes them explicitly (and we already have an exception in this case actually). Currently, you are triggering deprecation notices all the time when using the method, even in the new way


// The parameters $invalidValue and following are ignored by the new
// API, as they are not present in the new interface anymore.
// You should use buildViolation() instead.
Expand Down Expand Up @@ -310,6 +316,12 @@ public function getPropertyPath($subPath = '')
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error(
'The parameters $invalidValue, $pluralization and $code are not supported anymore '.
'as of Symfony 2.5 and will be removed in Symfony 3.0. Please use buildViolation() instead.',
E_USER_DEPRECATED
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be removed here. This is a bad method call already


throw new BadMethodCallException(
'addViolationAt() is not supported anymore as of Symfony 2.5. '.
'Please use buildViolation() instead or enable the legacy mode.'
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Validator/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public function __construct(GlobalExecutionContextInterface $globalContext, Tran
*/
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error(
'The parameters $invalidValue, $pluralization and $code are not supported anymore '.
'as of Symfony 2.5 and will be removed in Symfony 3.0. Please use buildViolation() instead.',
E_USER_DEPRECATED
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be triggered only when they are passed explicitely (i.e. func_num_args() >= 2), to avoid triggering notices for the new API way


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this log is useful because the whole class and the interface are deprecated, as they were moved to the Symfony\Component\Validator\Context namespace.

if (null === $plural) {
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
} else {
Expand Down Expand Up @@ -120,6 +126,12 @@ public function addViolation($message, array $params = array(), $invalidValue =
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error(
'The parameters $invalidValue, $pluralization and $code are not supported anymore '.
'as of Symfony 2.5 and will be removed in Symfony 3.0. Please use buildViolation() instead.',
E_USER_DEPRECATED
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whole method is deprecated, not only arguments


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

$this->globalContext->getViolations()->add(new ConstraintViolation(
null === $plural
? $this->translator->trans($message, $parameters, $this->translationDomain)
Expand Down