<?php
namespace App\Entity\System\Sendgrid;
use Cms\CoreBundle\Model\Interfaces\Identifiable\IdentifiableInterface;
use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
use Cms\TenantBundle\Entity\TenantedEntity;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Ramsey\Uuid\UuidInterface;
/**
* Class SendgridDomain
* @package App\Entity\System\Sendgrid
*
* @ORM\Entity(
* repositoryClass = "App\Doctrine\Repository\System\Sendgrid\SendgridDomainRepository",
* )
* @ORM\Table(
* name = "sys__sendgrid_domain",
* uniqueConstraints = {
* @ORM\UniqueConstraint(
* name = "uidx__tenant__domain__subdomain",
* columns = {
* "tenant",
* "domain",
* },
* ),
* },
* )
*/
class SendgridDomain extends TenantedEntity implements JsonSerializable, LoggableInterface
{
/**
* @var SendgridConfig|null
*
* @ORM\ManyToOne(
* targetEntity = "App\Entity\System\Sendgrid\SendgridConfig",
* inversedBy = "domains",
* )
* @ORM\JoinColumn(
* name = "config",
* referencedColumnName = "id",
* nullable = false,
* onDelete = "CASCADE",
* )
*/
protected ?SendgridConfig $config = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = false,
* )
*/
protected ?string $domain = null;
/**
* @var array
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected array $validationDns = [];
/**
* @var array
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected array $validationDnsStatus = [];
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false,
* options = {
* "default" = false,
* },
* )
*/
protected bool $validationStatus = false;
/**
* @var array
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected array $domainDnsStatus = [];
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false,
* options = {
* "default" = false,
* },
* )
*/
protected bool $domainStatus = false;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $sendgridDomainAuthenticationId = null;
/**
* @return SendgridConfig|null
*/
public function getConfig(): ?SendgridConfig
{
return $this->config;
}
/**
* @param SendgridConfig $config
* @return $this
*/
public function setConfig(SendgridConfig $config): self
{
$this->config = $config;
return $this;
}
/**
* @return string|null
*/
public function getDomain(): ?string
{
return $this->domain;
}
/**
* @param string|null $domain
* @return $this
*/
public function setDomain(?string $domain): self
{
$this->domain = $domain;
return $this;
}
/**
* @return array
*/
public function getValidationDns(): array
{
return $this->validationDns;
}
/**
* @param array $validationDns
* @return $this
*/
public function setValidationDns(array $validationDns): self
{
$this->validationDns = $validationDns;
return $this;
}
/**
* @return array
*/
public function getValidationDnsStatus(): array
{
return $this->validationDnsStatus;
}
/**
* @param array $validationDnsStatus
* @return $this
*/
public function setValidationDnsStatus(array $validationDnsStatus): self
{
$this->validationDnsStatus = $validationDnsStatus;
return $this;
}
/**
* @return bool
*/
public function getValidationStatus(): bool
{
return $this->validationStatus;
}
/**
* @param bool $validationStatus
* @return $this
*/
public function setValidationStatus(bool $validationStatus): self
{
$this->validationStatus = $validationStatus;
return $this;
}
/**
* @return string|null
*/
public function getSendgridDomainAuthenticationId(): ?string
{
return $this->sendgridDomainAuthenticationId;
}
/**
* @param string|null $sendgridDomainAuthenticationId
* @return $this
*/
public function setSendgridDomainAuthenticationId(?string $sendgridDomainAuthenticationId): self
{
$this->sendgridDomainAuthenticationId = $sendgridDomainAuthenticationId;
return $this;
}
/**
* @return array
*/
public function getDomainDnsStatus(): array
{
return $this->domainDnsStatus;
}
/**
* @param array $domainDnsStatus
* @return $this
*/
public function setDomainDnsStatus(array $domainDnsStatus): self
{
$this->domainDnsStatus = $domainDnsStatus;
return $this;
}
/**
* @return bool
*/
public function getDomainStatus(): bool
{
return $this->domainStatus;
}
/**
* @param bool $domainStatus
* @return $this
*/
public function setDomainStatus(bool $domainStatus): self
{
$this->domainStatus = $domainStatus;
return $this;
}
/**
* @return bool
*/
public function isSetup(): bool
{
return boolval($this->getSendgridDomainAuthenticationId());
}
/**
* @return bool
*/
public function isCompleted(): bool
{
return $this->getDomainStatus();
}
/**
* @return bool
*/
public function isVerified(): bool
{
return $this->getValidationStatus();
}
/**
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
static $refl = null;
$formatter = static function ($value, callable $formatter) {
switch (true) {
case is_scalar($value):
return $value;
case is_array($value):
$data = [];
foreach ($value as $k => $v) {
$data[$k] = $formatter($v, $formatter);
}
ksort($data);
return $data;
case $value instanceof UuidInterface:
return $value->__toString();
case $value instanceof IdentifiableInterface:
return $value->getId();
case $value instanceof \DateTimeInterface:
return $value->format(\DateTimeInterface::RFC3339);
case $value instanceof JsonSerializable:
return $value->jsonSerialize();
default:
return null;
}
};
if ( ! $refl) {
$refl = new \ReflectionObject($this);
}
$data = [];
foreach ($refl->getProperties(\ReflectionProperty::IS_PROTECTED) as $property) {
$property->setAccessible(true);
$data[$property->getName()] = $formatter(
$property->getValue($this),
$formatter
);
$property->setAccessible(false);
}
ksort($data);
return $data;
}
/**
* {@inheritDoc}
*/
public function getLoggableDetails(): array
{
return [
'id' => (string) $this->getId(),
'title' => $this->getDomain(),
];
}
}