Skip to content

[Validator] Add deprecated logs on addViolation() and addViolationAt() methods #13219

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
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
6 changes: 1 addition & 5 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function addViolation($message, array $parameters = array(), $invalidValu
// You should use buildViolation() instead.
if (func_num_args() > 2) {
throw new BadMethodCallException(
'The parameters $invalidValue, $pluralization and $code are '.
'The parameters $invalidValue, $plural and $code are '.
'not supported anymore as of Symfony 2.5. Please use '.
'buildViolation() instead or enable the legacy mode.'
);
Expand Down Expand Up @@ -321,8 +321,6 @@ public function addViolationAt($subPath, $message, array $parameters = array(),
*/
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
{
trigger_error('ExecutionContext::validate() is deprecated since version 2.5 and will be removed in 3.0. Use ExecutionContext::getValidator() together with inContext() instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'validate() is not supported anymore as of Symfony 2.5. '.
'Please use getValidator() instead or enable the legacy mode.'
Expand All @@ -334,8 +332,6 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
*/
public function validateValue($value, $constraints, $subPath = '', $groups = null)
{
trigger_error('ExecutionContext::validateValue() is deprecated since version 2.5 and will be removed in 3.0. Use ExecutionContext::getValidator() together with inContext() instead.', E_USER_DEPRECATED);

throw new BadMethodCallException(
'validateValue() is not supported anymore as of Symfony 2.5. '.
'Please use getValidator() instead or enable the legacy mode.'
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Validator/Context/LegacyExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function __construct(ValidatorInterface $validator, $root, MetadataFactor
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
if (func_num_args() > 2) {
trigger_error('The parameters $invalidValue, $plural and $code of '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Please use buildViolation() instead.', E_USER_DEPRECATED);

$this
->buildViolation($message, $parameters)
->setInvalidValue($invalidValue)
Expand All @@ -77,6 +79,11 @@ public function addViolation($message, array $parameters = array(), $invalidValu
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error(
Copy link
Member

Choose a reason for hiding this comment

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

Single line

'The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Please use buildViolation() instead.',
E_USER_DEPRECATED
);

if (func_num_args() > 2) {
$this
->buildViolation($message, $parameters)
Expand All @@ -102,6 +109,8 @@ public function addViolationAt($subPath, $message, array $parameters = array(),
*/
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use getValidator() together with inContext() instead.', E_USER_DEPRECATED);

if (is_array($value)) {
// The $traverse flag is ignored for arrays
$constraint = new Valid(array('traverse' => true, 'deep' => $deep));
Expand Down Expand Up @@ -138,6 +147,8 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
*/
public function validateValue($value, $constraints, $subPath = '', $groups = null)
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use getValidator() together with inContext() instead.', E_USER_DEPRECATED);

return $this
->getValidator()
->inContext($this)
Expand All @@ -151,6 +162,8 @@ public function validateValue($value, $constraints, $subPath = '', $groups = nul
*/
public function getMetadataFactory()
{
trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use getValidator() together with getMetadataFor() or hasMetadataFor instead.', E_USER_DEPRECATED);

return $this->metadataFactory;
}
}
9 changes: 9 additions & 0 deletions src/Symfony/Component/Validator/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public function __construct(GlobalExecutionContextInterface $globalContext, Tran
*/
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null)
{
if (func_num_args() > 2) {
trigger_error('The parameters $invalidValue, $plural and $code of '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Please use buildViolation() of the new validation API instead.', E_USER_DEPRECATED);
}

if (null === $plural) {
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
} else {
Expand Down Expand Up @@ -120,6 +124,11 @@ public function addViolation($message, array $params = array(), $invalidValue =
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
trigger_error(
Copy link
Member

Choose a reason for hiding this comment

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

Single line

'The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Please use buildViolation() of the new validation API instead.',
E_USER_DEPRECATED
);

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