Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace App\Validator\Model;
- use App\Exception\InvalidDTOException;
- use Symfony\Component\Validator\ConstraintViolationList;
- use Symfony\Component\Validator\Validator\ValidatorInterface;
- final class DTOValidator implements DTOValidatorInterface
- {
- /** @var ValidatorInterface */
- private $validator;
- public function __construct(ValidatorInterface $validator)
- {
- $this->validator = $validator;
- }
- public function validate(...$DTOs): void
- {
- $validationResults = new ConstraintViolationList();
- foreach ($DTOs as $DTO) {
- $validationResults->addAll($this->validator->validate($DTO));
- }
- if (0 !== count($validationResults)) {
- throw new InvalidDTOException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement