Skip to content

Commit e840634

Browse files
committed
[Validator] Add deprecated logs on addViolation() and addViolationAt() methods.
1 parent 193d69c commit e840634

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/Symfony/Component/Validator/Context/ExecutionContext.php

-4
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ public function addViolationAt($subPath, $message, array $parameters = array(),
321321
*/
322322
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
323323
{
324-
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);
325-
326324
throw new BadMethodCallException(
327325
'validate() is not supported anymore as of Symfony 2.5. '.
328326
'Please use getValidator() instead or enable the legacy mode.'
@@ -334,8 +332,6 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
334332
*/
335333
public function validateValue($value, $constraints, $subPath = '', $groups = null)
336334
{
337-
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);
338-
339335
throw new BadMethodCallException(
340336
'validateValue() is not supported anymore as of Symfony 2.5. '.
341337
'Please use getValidator() instead or enable the legacy mode.'

src/Symfony/Component/Validator/Context/LegacyExecutionContext.php

+16
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public function __construct(ValidatorInterface $validator, $root, MetadataFactor
5858
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
5959
{
6060
if (func_num_args() > 2) {
61+
trigger_error(
62+
'The parameters $invalidValue, $pluralization and $code of '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Please use buildViolation() instead.',
63+
E_USER_DEPRECATED
64+
);
65+
6166
$this
6267
->buildViolation($message, $parameters)
6368
->setInvalidValue($invalidValue)
@@ -77,6 +82,11 @@ public function addViolation($message, array $parameters = array(), $invalidValu
7782
*/
7883
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
7984
{
85+
trigger_error(
86+
'The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Please use buildViolation() instead.',
87+
E_USER_DEPRECATED
88+
);
89+
8090
if (func_num_args() > 2) {
8191
$this
8292
->buildViolation($message, $parameters)
@@ -102,6 +112,8 @@ public function addViolationAt($subPath, $message, array $parameters = array(),
102112
*/
103113
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
104114
{
115+
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);
116+
105117
if (is_array($value)) {
106118
// The $traverse flag is ignored for arrays
107119
$constraint = new Valid(array('traverse' => true, 'deep' => $deep));
@@ -138,6 +150,8 @@ public function validate($value, $subPath = '', $groups = null, $traverse = fals
138150
*/
139151
public function validateValue($value, $constraints, $subPath = '', $groups = null)
140152
{
153+
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);
154+
141155
return $this
142156
->getValidator()
143157
->inContext($this)
@@ -151,6 +165,8 @@ public function validateValue($value, $constraints, $subPath = '', $groups = nul
151165
*/
152166
public function getMetadataFactory()
153167
{
168+
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);
169+
154170
return $this->metadataFactory;
155171
}
156172
}

src/Symfony/Component/Validator/ExecutionContext.php

+12
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public function __construct(GlobalExecutionContextInterface $globalContext, Tran
9292
*/
9393
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null)
9494
{
95+
trigger_error(
96+
'The parameters $invalidValue, $pluralization and $code are not supported anymore '.
97+
'as of Symfony 2.5 and will be removed in Symfony 3.0. Please use buildViolation() instead.',
98+
E_USER_DEPRECATED
99+
);
100+
95101
if (null === $plural) {
96102
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
97103
} else {
@@ -120,6 +126,12 @@ public function addViolation($message, array $params = array(), $invalidValue =
120126
*/
121127
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
122128
{
129+
trigger_error(
130+
'The parameters $invalidValue, $pluralization and $code are not supported anymore '.
131+
'as of Symfony 2.5 and will be removed in Symfony 3.0. Please use buildViolation() instead.',
132+
E_USER_DEPRECATED
133+
);
134+
123135
$this->globalContext->getViolations()->add(new ConstraintViolation(
124136
null === $plural
125137
? $this->translator->trans($message, $parameters, $this->translationDomain)

0 commit comments

Comments
 (0)