/
mistercode
/
calculate-price
Обзор
Документация
Войти
/
mistercode
/
calculate-price
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/Validator/PaymentProcessorValidator.php
25 строк
716 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; class PaymentProcessorValidator extends ConstraintValidator { private const ALLOWED_PROCESSORS = ['paypal', 'stripe']; public function validate($value, Constraint $constraint): void { if (null === $value) { return; } if (!in_array($value, self::ALLOWED_PROCESSORS)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $value) ->setParameter('{{ allowed_values }}', implode(', ', self::ALLOWED_PROCESSORS)) ->addViolation(); } } }