/
mistercode
/
calculate-price
Обзор
Документация
Войти
/
mistercode
/
calculate-price
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/Validator/CouponValidator.php
28 строк
747 B
codefinecode
Tests (with AppTestFixtures), some fixes
09 фев 2025, 13:12
09 фев 2025, 13:12
f6fae59
Код
Авторство
О чём код?
<?php namespace App\Validator; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use App\Repository\CouponRepository; class CouponValidator extends ConstraintValidator { public function __construct(private CouponRepository $couponRepository) { } public function validate($value, Constraint $constraint) { if (!is_string($value) || '' === $value) { return; } if (!$this->couponRepository->findOneByCode($value)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $value) ->setCode(Coupon::NO_SUCH_COUPON_ERROR) ->addViolation(); } } }