src/Cms/DomainBundle/Entity/SslCertificate.php line 37

Open in your IDE?
  1. <?php
  2. namespace Cms\DomainBundle\Entity;
  3. use Cms\CoreBundle\Util\DateTimeUtils;
  4. use Cms\DomainBundle\Entity\Embeddables\SslCertificateDataEmbeddable;
  5. use Cms\DomainBundle\Entity\SslCertificates\CustomSslCertificate;
  6. use Cms\DomainBundle\Entity\SslCertificates\LetsEncryptSslCertificate;
  7. use Cms\TenantBundle\Entity\TenantedEntity;
  8. use DateTime;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * Class SslCertificate
  12.  * @package Cms\DomainBundle\Entity
  13.  *
  14.  * @ORM\Entity(
  15.  *     repositoryClass = "Cms\DomainBundle\Doctrine\SslCertificateRepository"
  16.  * )
  17.  *
  18.  * @ORM\InheritanceType("SINGLE_TABLE")
  19.  *
  20.  * @ORM\DiscriminatorColumn(
  21.  *     name = "_discr",
  22.  *     type = "string"
  23.  * )
  24.  *
  25.  * @ORM\DiscriminatorMap({
  26.  *     CustomSslCertificate::DISCR = "Cms\DomainBundle\Entity\SslCertificates\CustomSslCertificate",
  27.  *     LetsEncryptSslCertificate::DISCR = "Cms\DomainBundle\Entity\SslCertificates\LetsEncryptSslCertificate"
  28.  * })
  29.  *
  30.  * @ORM\Table(
  31.  *      name = "cms__domain__ssl_certificate"
  32.  * )
  33.  */
  34. abstract class SslCertificate extends TenantedEntity
  35. {
  36.     const DISCR null;
  37.     /**
  38.      * @var Domain
  39.      *
  40.      * @ORM\OneToOne(
  41.      *     targetEntity = "Domain"
  42.      * )
  43.      * @ORM\JoinColumn(
  44.      *     name = "domain",
  45.      *     nullable = false,
  46.      *     referencedColumnName = "id",
  47.      *     onDelete = "CASCADE"
  48.      * )
  49.      */
  50.     protected $domain;
  51.     /**
  52.      * When a cert is prepared and this is marked as ready, this should be set to the expiration of the cert.
  53.      * This cached expiration is useful in knowing when a cert expires without having to always parse the cert.
  54.      *
  55.      * @var DateTime
  56.      *
  57.      * @ORM\Column(
  58.      *     type = "datetime",
  59.      *     nullable = true
  60.      * )
  61.      */
  62.     protected $expiration;
  63.     /**
  64.      * @var SslCertificateDataEmbeddable
  65.      *
  66.      * @ORM\Embedded(
  67.      *     class = "Cms\DomainBundle\Entity\Embeddables\SslCertificateDataEmbeddable",
  68.      *     columnPrefix = "data_"
  69.      * )
  70.      */
  71.     protected $data;
  72.     /**
  73.      * @var bool
  74.      *
  75.      * @ORM\Column(
  76.      *     type = "boolean",
  77.      *     nullable = false,
  78.      *     options = {
  79.      *         "default" = false
  80.      *     }
  81.      * )
  82.      */
  83.     protected $ready false;
  84.     /**
  85.      * @var array|null
  86.      *
  87.      * @ORM\Column(
  88.      *     type = "json",
  89.      *     nullable = true,
  90.      * )
  91.      */
  92.     protected ?array $error null;
  93.     /**
  94.      * {@inheritdoc}
  95.      */
  96.     public function __construct()
  97.     {
  98.         $this->data = new SslCertificateDataEmbeddable();
  99.     }
  100.     /**
  101.      * @return Domain
  102.      */
  103.     public function getDomain()
  104.     {
  105.         return $this->domain;
  106.     }
  107.     /**
  108.      * @param Domain $value
  109.      * @return $this
  110.      */
  111.     public function setDomain(Domain $value)
  112.     {
  113.         $this->domain $value;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @return bool
  118.      */
  119.     public function isExpired(): bool
  120.     {
  121.         return $this->getExpiration() && ($this->getExpiration() < DateTimeUtils::now());
  122.     }
  123.     /**
  124.      * @return DateTime
  125.      */
  126.     public function getExpiration()
  127.     {
  128.         return $this->expiration;
  129.     }
  130.     /**
  131.      * @param DateTime $value
  132.      * @return $this
  133.      */
  134.     public function setExpiration(DateTime $value null)
  135.     {
  136.         $this->expiration $value;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return SslCertificateDataEmbeddable
  141.      */
  142.     public function getData()
  143.     {
  144.         return $this->data;
  145.     }
  146.     /**
  147.      * @return bool
  148.      */
  149.     public function isReady()
  150.     {
  151.         return ($this->getReady() === true);
  152.     }
  153.     /**
  154.      * @return bool
  155.      */
  156.     public function getReady()
  157.     {
  158.         return ($this->ready === true);
  159.     }
  160.     /**
  161.      * @param bool $value
  162.      * @return $this
  163.      */
  164.     public function setReady($value)
  165.     {
  166.         $this->ready = ($value === true);
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return string
  171.      */
  172.     public function getType()
  173.     {
  174.         $type '';
  175.         switch (static::DISCR) {
  176.             case LetsEncryptSslCertificate::DISCR:
  177.                 $type 'Let\'s Encrypt';
  178.                 break;
  179.             case CustomSslCertificate::DISCR:
  180.                 $type 'Custom';
  181.                 break;
  182.         }
  183.         return $type;
  184.     }
  185.     /**
  186.      * @return array|null
  187.      */
  188.     public function getError(): ?array
  189.     {
  190.         return $this->error;
  191.     }
  192.     /**
  193.      * @param array|null $error
  194.      * @return self
  195.      */
  196.     public function setError(?array $error): self
  197.     {
  198.         $this->error $error;
  199.         return $this;
  200.     }
  201. }