| @@ 12-36 (lines=25) @@ | ||
| 9 | use Symfony\Component\Validator\Constraint; |
|
| 10 | use Symfony\Component\Validator\ConstraintValidator; |
|
| 11 | ||
| 12 | final class CartExistsValidator extends ConstraintValidator |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var OrderRepositoryInterface |
|
| 16 | */ |
|
| 17 | private $orderRepository; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @param OrderRepositoryInterface $orderRepository |
|
| 21 | */ |
|
| 22 | public function __construct(OrderRepositoryInterface $orderRepository) |
|
| 23 | { |
|
| 24 | $this->orderRepository = $orderRepository; |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * {@inheritdoc} |
|
| 29 | */ |
|
| 30 | public function validate($token, Constraint $constraint) |
|
| 31 | { |
|
| 32 | if (null === $this->orderRepository->findOneBy(['tokenValue' => $token, 'state' => OrderInterface::STATE_CART])) { |
|
| 33 | $this->context->addViolation($constraint->message); |
|
| 34 | } |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| @@ 11-37 (lines=27) @@ | ||
| 8 | use Symfony\Component\Validator\Constraint; |
|
| 9 | use Symfony\Component\Validator\ConstraintValidator; |
|
| 10 | ||
| 11 | final class ProductVariantExistsValidator extends ConstraintValidator |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var ProductVariantRepositoryInterface |
|
| 15 | */ |
|
| 16 | private $productVariantRepository; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @param ProductVariantRepositoryInterface $productVariantRepository |
|
| 20 | */ |
|
| 21 | public function __construct(ProductVariantRepositoryInterface $productVariantRepository) |
|
| 22 | { |
|
| 23 | $this->productVariantRepository = $productVariantRepository; |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * {@inheritdoc} |
|
| 28 | */ |
|
| 29 | public function validate($productVariantCode, Constraint $constraint) |
|
| 30 | { |
|
| 31 | $product = $this->productVariantRepository->findOneBy(['code' => $productVariantCode]); |
|
| 32 | ||
| 33 | if (null === $product) { |
|
| 34 | $this->context->addViolation($constraint->message); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| @@ 11-35 (lines=25) @@ | ||
| 8 | use Symfony\Component\Validator\Constraint; |
|
| 9 | use Symfony\Component\Validator\ConstraintValidator; |
|
| 10 | ||
| 11 | final class TokenIsNotUsedValidator extends ConstraintValidator |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var OrderRepositoryInterface |
|
| 15 | */ |
|
| 16 | private $orderRepository; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @param OrderRepositoryInterface $orderRepository |
|
| 20 | */ |
|
| 21 | public function __construct(OrderRepositoryInterface $orderRepository) |
|
| 22 | { |
|
| 23 | $this->orderRepository = $orderRepository; |
|
| 24 | } |
|
| 25 | ||
| 26 | /** |
|
| 27 | * {@inheritdoc} |
|
| 28 | */ |
|
| 29 | public function validate($token, Constraint $constraint) |
|
| 30 | { |
|
| 31 | if (null !== $this->orderRepository->findOneBy(['tokenValue' => $token])) { |
|
| 32 | $this->context->addViolation($constraint->message); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| @@ 11-37 (lines=27) @@ | ||
| 8 | use Symfony\Component\Validator\Constraint; |
|
| 9 | use Symfony\Component\Validator\ConstraintValidator; |
|
| 10 | ||
| 11 | final class AddressExistsValidator extends ConstraintValidator |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var AddressRepositoryInterface |
|
| 15 | */ |
|
| 16 | private $addressRepository; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * AddressExistsValidator constructor. |
|
| 20 | * |
|
| 21 | * @param AddressRepositoryInterface $addressRepository |
|
| 22 | */ |
|
| 23 | public function __construct(AddressRepositoryInterface $addressRepository) |
|
| 24 | { |
|
| 25 | $this->addressRepository = $addressRepository; |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * {@inheritdoc} |
|
| 30 | */ |
|
| 31 | public function validate($id, Constraint $constraint) |
|
| 32 | { |
|
| 33 | if (null === $this->addressRepository->findOneBy(['id' => $id])) { |
|
| 34 | $this->context->addViolation($constraint->message); |
|
| 35 | } |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||