src/Form/Validator/Constraints/PhoneAndEmailNotBlank.php line 38

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2022 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2022 TECLA Consulting Group oü
  16.  */
  17. namespace App\Form\Validator\Constraints;
  18. use Symfony\Component\Validator\Constraint;
  19. use Symfony\Component\Validator\Exception\MissingOptionsException;
  20. final class PhoneAndEmailNotBlank extends Constraint
  21. {
  22.     public const IS_BLANK_PHONE_AND_EMAIL_ERROR '16107a97-2402-4a3c-b3fc-a7e9ff8c47d3';
  23.     public string $message 'Phone and e-mail should not be empty.';
  24.     public ?string $phonePropertyPath null;
  25.     public ?string $emailPropertyPath null;
  26.     protected static $errorNames = [
  27.         self::IS_BLANK_PHONE_AND_EMAIL_ERROR => 'IS_BLANK_PHONE_AND_EMAIL_ERROR',
  28.     ];
  29.     public function __construct(
  30.         array $options null,
  31.         ?array $groups null,
  32.         mixed $payload null,
  33.         ?string $message null,
  34.         ?string $phonePropertyPath null,
  35.         ?string $emailPropertyPath null
  36.     ) {
  37.         parent::__construct($options ?? [], $groups$payload);
  38.         $this->message $message ?? $this->message;
  39.         $this->phonePropertyPath $phonePropertyPath ?? $this->phonePropertyPath;
  40.         $this->emailPropertyPath $emailPropertyPath ?? $this->emailPropertyPath;
  41.         if (null === $this->phonePropertyPath) {
  42.             throw new MissingOptionsException(sprintf('Option "phonePropertyPath" must be given for constraint "%s".'__CLASS__), ['phonePropertyPath']);
  43.         }
  44.         if (null === $this->emailPropertyPath) {
  45.             throw new MissingOptionsException(sprintf('Option "emailPropertyPath" must be given for constraint "%s".'__CLASS__), ['emailPropertyPath']);
  46.         }
  47.     }
  48.     public function getTargets(): array|string
  49.     {
  50.         return self::CLASS_CONSTRAINT;
  51.     }
  52. }