Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #21111 [Validator] add groups support to the Valid constraint…
… (xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [Validator] add groups support to the Valid constraint | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #3622, #17622 | License | MIT | Doc PR | TODO Commits ------- 0ca27cc add groups support to the Valid constraint
- Loading branch information
Showing
6 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Symfony/Component/Validator/Constraints/ValidValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
|
||
/** | ||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de> | ||
*/ | ||
class ValidValidator extends ConstraintValidator | ||
{ | ||
public function validate($value, Constraint $constraint) | ||
{ | ||
if (!$constraint instanceof Valid) { | ||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid'); | ||
} | ||
|
||
$violations = $this->context->getValidator()->validate($value, null, array($this->context->getGroup())); | ||
|
||
foreach ($violations as $violation) { | ||
$this->context->buildViolation($violation->getMessage(), $violation->getParameters()) | ||
->atPath($violation->getPropertyPath()) | ||
->addViolation(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters