src/CmsBundle/Entity/Redirect.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\CmsBundle\Entity;
  3. use App\CasinoBundle\Entity\DateTrait;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\HttpFoundation\File\UploadedFile;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(
  10.  *     repositoryClass="App\CmsBundle\Repository\RedirectRepository"
  11.  * )
  12.  * @UniqueEntity(
  13.  *     fields={"site", "path"},
  14.  *     errorPath="path",
  15.  *     message="This path is already in use for this site."
  16.  * )
  17.  * @ORM\Table(
  18.  *     name="redirect",
  19.  *     indexes={
  20.  *         @ORM\Index(name="redirect_site_index", columns={"site_id"}),
  21.  *         @ORM\Index(name="redirect_published_index", columns={"published"}),
  22.  *         @ORM\Index(name="redirect_path_index", columns={"path"}),
  23.  *         @ORM\Index(name="redirect_pattern_index", columns={"pattern"})
  24.  *     }
  25.  * )
  26.  * @ORM\HasLifecycleCallbacks()
  27.  */
  28. class Redirect
  29. {
  30.     use IdTraitTitleTraitSiteTraitPublishedTraitPathTraitTimeStampedTrait;
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site", inversedBy="redirects")
  33.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  34.      */
  35.     private $site;
  36.     /**
  37.      * @ORM\Column(
  38.      *     type="boolean", options={"default":"0"}, nullable=false
  39.      * )
  40.      */
  41.     private $pattern;
  42.     /**
  43.      * @ORM\Column(
  44.      *     type="integer",
  45.      *     options={"default" : "301"}
  46.      * )
  47.      */
  48.     private $statusCode 301;
  49.     /**
  50.      * @ORM\Column(
  51.      *     type="string",
  52.      *     length=255
  53.      * )
  54.      */
  55.     private $targetPath;
  56.     public function setPath(string $path): self
  57.     {
  58.         $this->path $path;
  59.         $this->setPattern((str_contains($path'%') or str_contains($path'_')));
  60.         return $this;
  61.     }
  62.     public function __construct()
  63.     {
  64.         $this->pattern false;
  65.     }
  66.     /**
  67.      * @return string|null
  68.      */
  69.     public function getTargetPath(): ?string
  70.     {
  71.         return $this->targetPath;
  72.     }
  73.     /**
  74.      * @param string $targetPath
  75.      * @return $this
  76.      */
  77.     public function setTargetPath(string $targetPath): self
  78.     {
  79.         $this->targetPath $targetPath;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return int
  84.      */
  85.     public function getStatusCode(): int
  86.     {
  87.         return $this->statusCode;
  88.     }
  89.     /**
  90.      * @param int $statusCode
  91.      * @return $this
  92.      */
  93.     public function setStatusCode(int $statusCode): self
  94.     {
  95.         $this->statusCode $statusCode;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return bool
  100.      */
  101.     public function getPattern(): bool
  102.     {
  103.         return $this->pattern;
  104.     }
  105.     /**
  106.      * @param bool $pattern
  107.      * @return $this
  108.      */
  109.     public function setPattern(bool $pattern): self
  110.     {
  111.         $this->pattern $pattern;
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return array
  116.      */
  117.     public function getLoggableInformation(): array
  118.     {
  119.         return [
  120.             'id' => $this->getId(),
  121.             'site' => $this->getSite()?->getDomain(),
  122.             'path' => $this->getPath(),
  123.             'target_path' => $this->getTargetPath(),
  124.             'title' => $this->getTitle(),
  125.             'status_code' => $this->getStatusCode(),
  126.             'published' => $this->getPublished()
  127.         ];
  128.     }
  129. }