src/Invoice/Validator/Constraints/InvoicePaymentNotificationUnique.php line 40

  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\Invoice\Validator\Constraints;
  18. use Symfony\Component\Validator\Constraint;
  19. use Symfony\Component\Validator\Exception\MissingOptionsException;
  20. final class InvoicePaymentNotificationUnique extends Constraint
  21. {
  22.     public const NOT_UNIQUE_ERROR '1acfa1b7-ca8d-4ad6-8715-a6c530023593';
  23.     public string $message 'Invoice payment notification is not unique.';
  24.     public ?string $subscriberPropertyPath null;
  25.     public ?string $supplierPropertyPath null;
  26.     public ?string $customerPropertyPath null;
  27.     protected static $errorNames = [
  28.         self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
  29.     ];
  30.     public function __construct(
  31.         array $options null,
  32.         ?array $groups null,
  33.         mixed $payload null,
  34.         ?string $message null,
  35.         ?string $subscriberPropertyPath null,
  36.         ?string $supplierPropertyPath null,
  37.         ?string $customerPropertyPath null
  38.     ) {
  39.         parent::__construct($options ?? [], $groups$payload);
  40.         $this->message $message ?? $this->message;
  41.         $this->subscriberPropertyPath $subscriberPropertyPath ?? $this->subscriberPropertyPath;
  42.         $this->supplierPropertyPath $supplierPropertyPath ?? $this->supplierPropertyPath;
  43.         $this->customerPropertyPath $customerPropertyPath ?? $this->customerPropertyPath;
  44.         if (null === $this->subscriberPropertyPath) {
  45.             throw new MissingOptionsException(sprintf('Option "subscriberPropertyPath" must be given for constraint "%s".'__CLASS__), ['subscriberPropertyPath']);
  46.         }
  47.         if (null === $this->supplierPropertyPath) {
  48.             throw new MissingOptionsException(sprintf('Option "supplierPropertyPath" must be given for constraint "%s".'__CLASS__), ['supplierPropertyPath']);
  49.         }
  50.         if (null === $this->customerPropertyPath) {
  51.             throw new MissingOptionsException(sprintf('Option "customerPropertyPath" must be given for constraint "%s".'__CLASS__), ['customerPropertyPath']);
  52.         }
  53.     }
  54.     public function getTargets(): array|string
  55.     {
  56.         return self::CLASS_CONSTRAINT;
  57.     }
  58. }