Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3914ce0

Browse files
committed
add the getCause() to the ConstraintViolationInterface
1 parent 6b56480 commit 3914ce0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/Symfony/Component/Form/Extension/DataCollector/FormDataExtractor.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ public function extractSubmittedData(FormInterface $form): array
9898
while (null !== $cause) {
9999
if ($cause instanceof ConstraintViolationInterface) {
100100
$errorData['trace'][] = $cause;
101-
$cause = method_exists($cause, 'getCause') ? $cause->getCause() : null;
101+
102+
if (method_exists($cause, 'getCause')) {
103+
$cause = $cause->getCause();
104+
} else {
105+
trigger_deprecation('symfony/validator', '6.2', 'Not implementing the getCause() method in "%s" is deprecated.', $cause::class);
106+
$cause = null;
107+
}
102108

103109
continue;
104110
}

src/Symfony/Component/Validator/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
6.2
55
---
66

7+
* Add method `getCause()` to `ConstraintViolationInterface`
78
* Add the `When` constraint and validator
89
* Deprecate the "loose" e-mail validation mode, use "html5" instead
910
* Add the `negate` option to the `Expression` constraint, to inverse the logic of the violation's creation

src/Symfony/Component/Validator/ConstraintViolationInterface.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*
3232
* @author Bernhard Schussek <[email protected]>
3333
*
34+
* @method mixed getCause() Returns the cause of the violation. Not implementing it is deprecated since Symfony 6.2.
3435
* @method string __toString() Converts the violation into a string for debugging purposes. Not implementing it is deprecated since Symfony 6.1.
3536
*/
3637
interface ConstraintViolationInterface

0 commit comments

Comments
 (0)