<?php
namespace Cms\DomainBundle\Entity;
use Cms\CoreBundle\Util\DateTimeUtils;
use Cms\DomainBundle\Entity\Embeddables\SslCertificateDataEmbeddable;
use Cms\DomainBundle\Entity\SslCertificates\CustomSslCertificate;
use Cms\DomainBundle\Entity\SslCertificates\LetsEncryptSslCertificate;
use Cms\TenantBundle\Entity\TenantedEntity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SslCertificate
* @package Cms\DomainBundle\Entity
*
* @ORM\Entity(
* repositoryClass = "Cms\DomainBundle\Doctrine\SslCertificateRepository"
* )
*
* @ORM\InheritanceType("SINGLE_TABLE")
*
* @ORM\DiscriminatorColumn(
* name = "_discr",
* type = "string"
* )
*
* @ORM\DiscriminatorMap({
* CustomSslCertificate::DISCR = "Cms\DomainBundle\Entity\SslCertificates\CustomSslCertificate",
* LetsEncryptSslCertificate::DISCR = "Cms\DomainBundle\Entity\SslCertificates\LetsEncryptSslCertificate"
* })
*
* @ORM\Table(
* name = "cms__domain__ssl_certificate"
* )
*/
abstract class SslCertificate extends TenantedEntity
{
const DISCR = null;
/**
* @var Domain
*
* @ORM\OneToOne(
* targetEntity = "Domain"
* )
* @ORM\JoinColumn(
* name = "domain",
* nullable = false,
* referencedColumnName = "id",
* onDelete = "CASCADE"
* )
*/
protected $domain;
/**
* When a cert is prepared and this is marked as ready, this should be set to the expiration of the cert.
* This cached expiration is useful in knowing when a cert expires without having to always parse the cert.
*
* @var DateTime
*
* @ORM\Column(
* type = "datetime",
* nullable = true
* )
*/
protected $expiration;
/**
* @var SslCertificateDataEmbeddable
*
* @ORM\Embedded(
* class = "Cms\DomainBundle\Entity\Embeddables\SslCertificateDataEmbeddable",
* columnPrefix = "data_"
* )
*/
protected $data;
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false,
* options = {
* "default" = false
* }
* )
*/
protected $ready = false;
/**
* @var array|null
*
* @ORM\Column(
* type = "json",
* nullable = true,
* )
*/
protected ?array $error = null;
/**
* {@inheritdoc}
*/
public function __construct()
{
$this->data = new SslCertificateDataEmbeddable();
}
/**
* @return Domain
*/
public function getDomain()
{
return $this->domain;
}
/**
* @param Domain $value
* @return $this
*/
public function setDomain(Domain $value)
{
$this->domain = $value;
return $this;
}
/**
* @return bool
*/
public function isExpired(): bool
{
return $this->getExpiration() && ($this->getExpiration() < DateTimeUtils::now());
}
/**
* @return DateTime
*/
public function getExpiration()
{
return $this->expiration;
}
/**
* @param DateTime $value
* @return $this
*/
public function setExpiration(DateTime $value = null)
{
$this->expiration = $value;
return $this;
}
/**
* @return SslCertificateDataEmbeddable
*/
public function getData()
{
return $this->data;
}
/**
* @return bool
*/
public function isReady()
{
return ($this->getReady() === true);
}
/**
* @return bool
*/
public function getReady()
{
return ($this->ready === true);
}
/**
* @param bool $value
* @return $this
*/
public function setReady($value)
{
$this->ready = ($value === true);
return $this;
}
/**
* @return string
*/
public function getType()
{
$type = '';
switch (static::DISCR) {
case LetsEncryptSslCertificate::DISCR:
$type = 'Let\'s Encrypt';
break;
case CustomSslCertificate::DISCR:
$type = 'Custom';
break;
}
return $type;
}
/**
* @return array|null
*/
public function getError(): ?array
{
return $this->error;
}
/**
* @param array|null $error
* @return self
*/
public function setError(?array $error): self
{
$this->error = $error;
return $this;
}
}