-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Added ConstraintViolation::getConstraint() #11657
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
UPGRADE FROM 2.5 to 2.6 | ||
======================= | ||
|
||
Validator | ||
--------- | ||
|
||
* The internal method `setConstraint()` was added to | ||
`Symfony\Component\Validator\Context\ExecutionContextInterface`. With | ||
this method, the context is informed about the constraint that is currently | ||
being validated. | ||
|
||
If you implement this interface, make sure to add the method to your | ||
implementation. The easiest solution is to just implement an empty method: | ||
|
||
```php | ||
public function setConstraint(Constraint $constraint) | ||
{ | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Symfony\Component\Validator\Context; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface; | ||
use Symfony\Component\Validator\Mapping\MetadataInterface; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
|
@@ -136,6 +137,16 @@ public function setNode($value, $object, MetadataInterface $metadata = null, $pr | |
*/ | ||
public function setGroup($group); | ||
|
||
/** | ||
* Sets the currently validated constraint. | ||
* | ||
* @param Constraint $constraint The validated constraint | ||
* | ||
* @internal Used by the validator engine. Should not be called by user | ||
* code. | ||
*/ | ||
public function setConstraint(Constraint $constraint); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the BC promise, this can must be documented in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also in the Validator changelog There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both updated. |
||
|
||
/** | ||
* Marks an object as validated in a specific validation group. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Validator\Violation; | ||
|
||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintViolation; | ||
use Symfony\Component\Validator\ConstraintViolationList; | ||
use Symfony\Component\Validator\Util\PropertyPath; | ||
|
@@ -72,12 +73,17 @@ class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface | |
*/ | ||
private $plural; | ||
|
||
/** | ||
* @var Constraint | ||
*/ | ||
private $constraint; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
private $code; | ||
|
||
public function __construct(ConstraintViolationList $violations, $message, array $parameters, $root, $propertyPath, $invalidValue, TranslatorInterface $translator, $translationDomain = null) | ||
public function __construct(ConstraintViolationList $violations, Constraint $constraint, $message, array $parameters, $root, $propertyPath, $invalidValue, TranslatorInterface $translator, $translationDomain = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I think you are right about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is indeed no guarantee, but the implementation should ensure that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be useful then to document the steps that have to be done to the docblock. |
||
{ | ||
$this->violations = $violations; | ||
$this->message = $message; | ||
|
@@ -87,6 +93,7 @@ public function __construct(ConstraintViolationList $violations, $message, array | |
$this->invalidValue = $invalidValue; | ||
$this->translator = $translator; | ||
$this->translationDomain = $translationDomain; | ||
$this->constraint = $constraint; | ||
} | ||
|
||
/** | ||
|
@@ -195,7 +202,8 @@ public function addViolation() | |
$this->propertyPath, | ||
$this->invalidValue, | ||
$this->plural, | ||
$this->code | ||
$this->code, | ||
$this->constraint | ||
)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this will be added to ConstraintViolationInterface for 3.0.
I think we need to keep track of such things. Maybe the easiest is to just add it as commented code in the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking to @fabpot about this once, but without a clear result. We should talk about this once he's back from vacation and make a definite decision.