src/App/Entity/System/Sendgrid/SendgridDomain.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity\System\Sendgrid;
  3. use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
  4. use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
  5. use Cms\TenantBundle\Entity\TenantedEntity;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JsonSerializable;
  8. use Ramsey\Uuid\UuidInterface;
  9. /**
  10.  * Class SendgridDomain
  11.  * @package App\Entity\System\Sendgrid
  12.  *
  13.  * @ORM\Entity(
  14.  *     repositoryClass = "App\Doctrine\Repository\System\Sendgrid\SendgridDomainRepository",
  15.  * )
  16.  * @ORM\Table(
  17.  *     name = "sys__sendgrid_domain",
  18.  *     uniqueConstraints = {
  19.  *         @ORM\UniqueConstraint(
  20.  *             name = "uidx__tenant__domain__subdomain",
  21.  *             columns = {
  22.  *                 "tenant",
  23.  *                 "domain",
  24.  *             },
  25.  *         ),
  26.  *     },
  27.  * )
  28.  */
  29. class SendgridDomain extends TenantedEntity implements JsonSerializableLoggableInterface
  30. {
  31.     /**
  32.      * @var SendgridConfig|null
  33.      *
  34.      * @ORM\ManyToOne(
  35.      *     targetEntity = "App\Entity\System\Sendgrid\SendgridConfig",
  36.      *     inversedBy = "domains",
  37.      * )
  38.      * @ORM\JoinColumn(
  39.      *     name = "config",
  40.      *     referencedColumnName = "id",
  41.      *     nullable = false,
  42.      *     onDelete = "CASCADE",
  43.      * )
  44.      */
  45.     protected ?SendgridConfig $config null;
  46.     /**
  47.      * @var string|null
  48.      *
  49.      * @ORM\Column(
  50.      *     type = "string",
  51.      *     nullable = false,
  52.      * )
  53.      */
  54.     protected ?string $domain null;
  55.     /**
  56.      * @var array
  57.      *
  58.      * @ORM\Column(
  59.      *     type = "json",
  60.      *     nullable = true,
  61.      * )
  62.      */
  63.     protected array $validationDns = [];
  64.     /**
  65.      * @var array
  66.      *
  67.      * @ORM\Column(
  68.      *     type = "json",
  69.      *     nullable = true,
  70.      * )
  71.      */
  72.     protected array $validationDnsStatus = [];
  73.     /**
  74.      * @var bool
  75.      *
  76.      * @ORM\Column(
  77.      *     type = "boolean",
  78.      *     nullable = false,
  79.      *     options = {
  80.      *         "default" = false,
  81.      *     },
  82.      * )
  83.      */
  84.     protected bool $validationStatus false;
  85.     /**
  86.      * @var array
  87.      *
  88.      * @ORM\Column(
  89.      *     type = "json",
  90.      *     nullable = true,
  91.      * )
  92.      */
  93.     protected array $domainDnsStatus = [];
  94.     /**
  95.      * @var bool
  96.      *
  97.      * @ORM\Column(
  98.      *     type = "boolean",
  99.      *     nullable = false,
  100.      *     options = {
  101.      *         "default" = false,
  102.      *     },
  103.      * )
  104.      */
  105.     protected bool $domainStatus false;
  106.     /**
  107.      * @var string|null
  108.      *
  109.      * @ORM\Column(
  110.      *     type = "string",
  111.      *     nullable = true,
  112.      * )
  113.      */
  114.     protected ?string $sendgridDomainAuthenticationId null;
  115.     /**
  116.      * @return SendgridConfig|null
  117.      */
  118.     public function getConfig(): ?SendgridConfig
  119.     {
  120.         return $this->config;
  121.     }
  122.     /**
  123.      * @param SendgridConfig $config
  124.      * @return $this
  125.      */
  126.     public function setConfig(SendgridConfig $config): self
  127.     {
  128.         $this->config $config;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return string|null
  133.      */
  134.     public function getDomain(): ?string
  135.     {
  136.         return $this->domain;
  137.     }
  138.     /**
  139.      * @param string|null $domain
  140.      * @return $this
  141.      */
  142.     public function setDomain(?string $domain): self
  143.     {
  144.         $this->domain $domain;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return array
  149.      */
  150.     public function getValidationDns(): array
  151.     {
  152.         return $this->validationDns;
  153.     }
  154.     /**
  155.      * @param array $validationDns
  156.      * @return $this
  157.      */
  158.     public function setValidationDns(array $validationDns): self
  159.     {
  160.         $this->validationDns $validationDns;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return array
  165.      */
  166.     public function getValidationDnsStatus(): array
  167.     {
  168.         return $this->validationDnsStatus;
  169.     }
  170.     /**
  171.      * @param array $validationDnsStatus
  172.      * @return $this
  173.      */
  174.     public function setValidationDnsStatus(array $validationDnsStatus): self
  175.     {
  176.         $this->validationDnsStatus $validationDnsStatus;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return bool
  181.      */
  182.     public function getValidationStatus(): bool
  183.     {
  184.         return $this->validationStatus;
  185.     }
  186.     /**
  187.      * @param bool $validationStatus
  188.      * @return $this
  189.      */
  190.     public function setValidationStatus(bool $validationStatus): self
  191.     {
  192.         $this->validationStatus $validationStatus;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return string|null
  197.      */
  198.     public function getSendgridDomainAuthenticationId(): ?string
  199.     {
  200.         return $this->sendgridDomainAuthenticationId;
  201.     }
  202.     /**
  203.      * @param string|null $sendgridDomainAuthenticationId
  204.      * @return $this
  205.      */
  206.     public function setSendgridDomainAuthenticationId(?string $sendgridDomainAuthenticationId): self
  207.     {
  208.         $this->sendgridDomainAuthenticationId $sendgridDomainAuthenticationId;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return array
  213.      */
  214.     public function getDomainDnsStatus(): array
  215.     {
  216.         return $this->domainDnsStatus;
  217.     }
  218.     /**
  219.      * @param array $domainDnsStatus
  220.      * @return $this
  221.      */
  222.     public function setDomainDnsStatus(array $domainDnsStatus): self
  223.     {
  224.         $this->domainDnsStatus $domainDnsStatus;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return bool
  229.      */
  230.     public function getDomainStatus(): bool
  231.     {
  232.         return $this->domainStatus;
  233.     }
  234.     /**
  235.      * @param bool $domainStatus
  236.      * @return $this
  237.      */
  238.     public function setDomainStatus(bool $domainStatus): self
  239.     {
  240.         $this->domainStatus $domainStatus;
  241.         return $this;
  242.     }
  243.     /**
  244.      * @return bool
  245.      */
  246.     public function isSetup(): bool
  247.     {
  248.         return boolval($this->getSendgridDomainAuthenticationId());
  249.     }
  250.     /**
  251.      * @return bool
  252.      */
  253.     public function isCompleted(): bool
  254.     {
  255.         return $this->getDomainStatus();
  256.     }
  257.     /**
  258.      * @return bool
  259.      */
  260.     public function isVerified(): bool
  261.     {
  262.         return $this->getValidationStatus();
  263.     }
  264.     /**
  265.      * {@inheritDoc}
  266.      */
  267.     public function jsonSerialize(): array
  268.     {
  269.         static $refl null;
  270.         $formatter = static function ($value, callable $formatter) {
  271.             switch (true) {
  272.                 case is_scalar($value):
  273.                     return $value;
  274.                 case is_array($value):
  275.                     $data = [];
  276.                     foreach ($value as $k => $v) {
  277.                         $data[$k] = $formatter($v$formatter);
  278.                     }
  279.                     ksort($data);
  280.                     return $data;
  281.                 case $value instanceof UuidInterface:
  282.                     return $value->__toString();
  283.                 case $value instanceof IdentifiableInterface:
  284.                     return $value->getId();
  285.                 case $value instanceof \DateTimeInterface:
  286.                     return $value->format(\DateTimeInterface::RFC3339);
  287.                 case $value instanceof JsonSerializable:
  288.                     return $value->jsonSerialize();
  289.                 default:
  290.                     return null;
  291.             }
  292.         };
  293.         if ( ! $refl) {
  294.             $refl = new \ReflectionObject($this);
  295.         }
  296.         $data = [];
  297.         foreach ($refl->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
  298.             $property->setAccessible(true);
  299.             $data[$property->getName()] = $formatter(
  300.                 $property->getValue($this),
  301.                 $formatter
  302.             );
  303.             $property->setAccessible(false);
  304.         }
  305.         ksort($data);
  306.         return $data;
  307.     }
  308.     /**
  309.      * {@inheritDoc}
  310.      */
  311.     public function getLoggableDetails(): array
  312.     {
  313.         return [
  314.             'id' => (string) $this->getId(),
  315.             'title' => $this->getDomain(),
  316.         ];
  317.     }
  318. }