| @@ 10-34 (lines=25) @@ | ||
| 7 | use Symfony\Component\Validator\Constraint; |
|
| 8 | use Symfony\Component\Validator\ConstraintValidator; |
|
| 9 | ||
| 10 | final class CartWithGivenTokenDoesNotExistsValidator extends ConstraintValidator |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var OrderRepositoryInterface |
|
| 14 | */ |
|
| 15 | private $orderRepository; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @param OrderRepositoryInterface $orderRepository |
|
| 19 | */ |
|
| 20 | public function __construct(OrderRepositoryInterface $orderRepository) |
|
| 21 | { |
|
| 22 | $this->orderRepository = $orderRepository; |
|
| 23 | } |
|
| 24 | ||
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public function validate($token, Constraint $constraint) |
|
| 29 | { |
|
| 30 | if (null === $this->orderRepository->findOneBy(['tokenValue' => $token, 'state' => OrderInterface::STATE_CART])) { |
|
| 31 | $this->context->addViolation($constraint->message); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| @@ 9-33 (lines=25) @@ | ||
| 6 | use Symfony\Component\Validator\Constraint; |
|
| 7 | use Symfony\Component\Validator\ConstraintValidator; |
|
| 8 | ||
| 9 | final class TokenAlreadyTakenValidator extends ConstraintValidator |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var OrderRepositoryInterface |
|
| 13 | */ |
|
| 14 | private $orderRepository; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param OrderRepositoryInterface $orderRepository |
|
| 18 | */ |
|
| 19 | public function __construct(OrderRepositoryInterface $orderRepository) |
|
| 20 | { |
|
| 21 | $this->orderRepository = $orderRepository; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * {@inheritdoc} |
|
| 26 | */ |
|
| 27 | public function validate($token, Constraint $constraint) |
|
| 28 | { |
|
| 29 | if (null !== $this->orderRepository->findOneBy(['tokenValue' => $token])) { |
|
| 30 | $this->context->addViolation($constraint->message); |
|
| 31 | } |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||