edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Validation\Constraints; |
||
| 4 | |||
| 5 | use Symfony\Component\Validator\Constraint; |
||
| 6 | use Symfony\Component\Validator\ConstraintValidator; |
||
| 7 | |||
| 8 | class DomainNameValidator extends ConstraintValidator |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Checks if the passed value is valid. |
||
| 13 | * |
||
| 14 | * @param string $domainName |
||
| 15 | * @param Constraint $constraint The constraint for the validation |
||
| 16 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
| 17 | */ |
||
| 18 | public function validate($domainName, Constraint $constraint): void |
||
| 19 | { |
||
| 20 | if (null === $domainName) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 21 | return; |
||
| 22 | } |
||
| 23 | if (false === filter_var($domainName, FILTER_VALIDATE_DOMAIN) |
||
| 24 | || false === \ts\stringContains($domainName, '.') |
||
| 25 | || false !== \ts\stringContains($domainName, '//') |
||
| 26 | ) { |
||
| 27 | $this->context->buildViolation(sprintf(DomainName::MESSAGE, $this->formatValue($domainName))) |
||
| 28 | ->setParameter('{{ value }}', $this->formatValue($domainName)) |
||
| 29 | ->setCode(DomainName::INVALID_DOMAIN_ERROR) |
||
| 30 | ->addViolation(); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } |
||
| 34 |