src/Cms/DomainBundle/Entity/Domain.php line 31

Open in your IDE?
  1. <?php
  2. namespace Cms\DomainBundle\Entity;
  3. use Cms\DomainBundle\Entity\Embeddables\DomainRedirectionEmbeddable;
  4. use Cms\TenantBundle\Entity\TenantedEntity;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * Class Domain
  8.  * @package Cms\DomainBundle\Entity
  9.  *
  10.  * @ORM\Entity(
  11.  *     repositoryClass = "Cms\DomainBundle\Doctrine\DomainRepository"
  12.  * )
  13.  *
  14.  * @ORM\Table(
  15.  *     name = "cms__domain__domain",
  16.  *     uniqueConstraints = {
  17.  *         @ORM\UniqueConstraint(
  18.  *             name = "idx_limit_subdomains",
  19.  *             columns = {
  20.  *                 "tenant",
  21.  *                 "apex",
  22.  *                 "name"
  23.  *             }
  24.  *         )
  25.  *     }
  26.  * )
  27.  */
  28. class Domain extends TenantedEntity
  29. {
  30.     /**
  31.      * @var Apex
  32.      *
  33.      * @ORM\ManyToOne(
  34.      *     targetEntity = "Apex",
  35.      *     inversedBy = "domains"
  36.      * )
  37.      *
  38.      * @ORM\JoinColumn(
  39.      *     name = "apex",
  40.      *     referencedColumnName = "id",
  41.      *     onDelete = "CASCADE"
  42.      * )
  43.      */
  44.     protected $apex;
  45.     /**
  46.      * @var string
  47.      *
  48.      * @ORM\Column(
  49.      *     type = "string",
  50.      *     nullable = false,
  51.      *     unique = false
  52.      * )
  53.      */
  54.     protected $name;
  55.     /**
  56.      * @var DomainRedirectionEmbeddable
  57.      *
  58.      * @ORM\Embedded(
  59.      *     class = "Cms\DomainBundle\Entity\Embeddables\DomainRedirectionEmbeddable",
  60.      *     columnPrefix = "redirection_"
  61.      * )
  62.      */
  63.     protected $redirection;
  64.     /**
  65.      * @var SslCertificate
  66.      *
  67.      * @ORM\OneToOne(
  68.      *     targetEntity = "SslCertificate",
  69.      *     cascade = {"remove"}
  70.      * )
  71.      *
  72.      * @ORM\JoinColumn(
  73.      *     name = "certificate",
  74.      *     referencedColumnName = "id",
  75.      *     onDelete = "SET NULL"
  76.      * )
  77.      */
  78.     protected $certificate;
  79.     /**
  80.      * The operating mode of SSL for the domain.
  81.      * This determines whether or not SSL is "forced".
  82.      *
  83.      * @var int
  84.      *
  85.      * @ORM\Column(
  86.      *     type = "boolean",
  87.      *     nullable = false,
  88.      *     options = {
  89.      *         "default" = false
  90.      *     }
  91.      * )
  92.      */
  93.     protected $httpsUpgrade false;
  94.     /**
  95.      * {@inheritdoc}
  96.      */
  97.     public function __construct()
  98.     {
  99.         $this->redirection = new DomainRedirectionEmbeddable();
  100.     }
  101.     /**
  102.      * {@inheritdoc}
  103.      */
  104.     public function getHost()
  105.     {
  106.         // if there is no apex, just return the name
  107.         // this would be used if like a domain way made on the fly for like intranet use
  108.         if (empty($this->getApex())) {
  109.             if (empty($this->getName())) {
  110.                 throw new \Exception();
  111.             }
  112.             return $this->getName();
  113.         }
  114.         if (empty($this->getName())) {
  115.             return $this->getApex()->getHost();
  116.         }
  117.         return sprintf(
  118.             '%s.%s',
  119.             $this->getName(),
  120.             $this->getApex()->getHost()
  121.         );
  122.     }
  123.     /**
  124.      * @return Apex
  125.      */
  126.     public function getApex()
  127.     {
  128.         return $this->apex;
  129.     }
  130.     /**
  131.      * @param Apex $value
  132.      * @return $this
  133.      */
  134.     public function setApex(Apex $value)
  135.     {
  136.         $this->apex $value;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return string
  141.      */
  142.     public function getName()
  143.     {
  144.         return $this->name;
  145.     }
  146.     /**
  147.      * @param string $value
  148.      * @return $this
  149.      */
  150.     public function setName($value)
  151.     {
  152.         $this->name $value;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return DomainRedirectionEmbeddable
  157.      */
  158.     public function getRedirection()
  159.     {
  160.         return $this->redirection;
  161.     }
  162.     /**
  163.      * @return bool
  164.      */
  165.     public function isRedirecting()
  166.     {
  167.         return $this->getRedirection()->isEnabled();
  168.     }
  169.     /**
  170.      * @return SslCertificate|null
  171.      */
  172.     public function getCertificate()
  173.     {
  174.         return $this->certificate;
  175.     }
  176.     /**
  177.      * @param SslCertificate|null $value
  178.      * @return $this
  179.      */
  180.     public function setCertificate(SslCertificate $value null)
  181.     {
  182.         $this->certificate $value;
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return bool
  187.      */
  188.     public function isHttpsUpgrade()
  189.     {
  190.         return ($this->getHttpsUpgrade() === true);
  191.     }
  192.     /**
  193.      * @return bool
  194.      */
  195.     public function getHttpsUpgrade()
  196.     {
  197.         return ($this->httpsUpgrade === true);
  198.     }
  199.     /**
  200.      * @param bool $value
  201.      * @return $this
  202.      */
  203.     public function setHttpsUpgrade($value)
  204.     {
  205.         $this->httpsUpgrade = ($value === true);
  206.         return $this;
  207.     }
  208.     /**
  209.      * HACK: used as a first stage to fix the redirection code logic that forces 302's everywhere.
  210.      *
  211.      * @return int
  212.      */
  213.     public function getRealCode(): int
  214.     {
  215.         if ($this->getTenant() && $this->getTenant()->hasRedirectCodes() && $this->getRedirection()) {
  216.             return $this->getRedirection()->getCode() ?: DomainRedirectionEmbeddable::TYPES__302;
  217.         }
  218.         return DomainRedirectionEmbeddable::TYPES__302;
  219.     }
  220. }