src/Invoice/Validator/Constraints/SupplierAndCustomerNotBlank.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\Invoice\Validator\Constraints;
  18. use Symfony\Component\Validator\Constraint;
  19. use Symfony\Component\Validator\Exception\MissingOptionsException;
  20. final class SupplierAndCustomerNotBlank extends Constraint
  21. {
  22.     public const IS_BLANK_SUPPLIER_AND_CUSTOMER_ERROR 'ef4aeb12-8851-4721-a3db-8eabd8a9f575';
  23.     public string $message 'Supplier and customer should not be empty.';
  24.     public ?string $supplierPropertyPath null;
  25.     public ?string $customerPropertyPath null;
  26.     protected static $errorNames = [
  27.         self::IS_BLANK_SUPPLIER_AND_CUSTOMER_ERROR => 'IS_BLANK_SUPPLIER_AND_CUSTOMER_ERROR',
  28.     ];
  29.     public function __construct(
  30.         array $options null,
  31.         ?array $groups null,
  32.         mixed $payload null,
  33.         ?string $message null,
  34.         ?string $supplierPropertyPath null,
  35.         ?string $customerPropertyPath null
  36.     ) {
  37.         parent::__construct($options ?? [], $groups$payload);
  38.         $this->message $message ?? $this->message;
  39.         $this->supplierPropertyPath $supplierPropertyPath ?? $this->supplierPropertyPath;
  40.         $this->customerPropertyPath $customerPropertyPath ?? $this->customerPropertyPath;
  41.         if (null === $this->supplierPropertyPath) {
  42.             throw new MissingOptionsException(sprintf('Option "supplierPropertyPath" must be given for constraint "%s".'__CLASS__), ['supplierPropertyPath']);
  43.         }
  44.         if (null === $this->customerPropertyPath) {
  45.             throw new MissingOptionsException(sprintf('Option "customerPropertyPath" must be given for constraint "%s".'__CLASS__), ['customerPropertyPath']);
  46.         }
  47.     }
  48.     public function getTargets(): array|string
  49.     {
  50.         return self::CLASS_CONSTRAINT;
  51.     }
  52. }