<?php
namespace App\CmsBundle\Entity;
use App\CasinoBundle\Entity\DateTrait;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(
* repositoryClass="App\CmsBundle\Repository\RedirectRepository"
* )
* @UniqueEntity(
* fields={"site", "path"},
* errorPath="path",
* message="This path is already in use for this site."
* )
* @ORM\Table(
* name="redirect",
* indexes={
* @ORM\Index(name="redirect_site_index", columns={"site_id"}),
* @ORM\Index(name="redirect_published_index", columns={"published"}),
* @ORM\Index(name="redirect_path_index", columns={"path"}),
* @ORM\Index(name="redirect_pattern_index", columns={"pattern"})
* }
* )
* @ORM\HasLifecycleCallbacks()
*/
class Redirect
{
use IdTrait, TitleTrait, SiteTrait, PublishedTrait, PathTrait, TimeStampedTrait;
/**
* @ORM\ManyToOne(targetEntity="App\CmsBundle\Entity\Site", inversedBy="redirects")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $site;
/**
* @ORM\Column(
* type="boolean", options={"default":"0"}, nullable=false
* )
*/
private $pattern;
/**
* @ORM\Column(
* type="integer",
* options={"default" : "301"}
* )
*/
private $statusCode = 301;
/**
* @ORM\Column(
* type="string",
* length=255
* )
*/
private $targetPath;
public function setPath(string $path): self
{
$this->path = $path;
$this->setPattern((str_contains($path, '%') or str_contains($path, '_')));
return $this;
}
public function __construct()
{
$this->pattern = false;
}
/**
* @return string|null
*/
public function getTargetPath(): ?string
{
return $this->targetPath;
}
/**
* @param string $targetPath
* @return $this
*/
public function setTargetPath(string $targetPath): self
{
$this->targetPath = $targetPath;
return $this;
}
/**
* @return int
*/
public function getStatusCode(): int
{
return $this->statusCode;
}
/**
* @param int $statusCode
* @return $this
*/
public function setStatusCode(int $statusCode): self
{
$this->statusCode = $statusCode;
return $this;
}
/**
* @return bool
*/
public function getPattern(): bool
{
return $this->pattern;
}
/**
* @param bool $pattern
* @return $this
*/
public function setPattern(bool $pattern): self
{
$this->pattern = $pattern;
return $this;
}
/**
* @return array
*/
public function getLoggableInformation(): array
{
return [
'id' => $this->getId(),
'site' => $this->getSite()?->getDomain(),
'path' => $this->getPath(),
'target_path' => $this->getTargetPath(),
'title' => $this->getTitle(),
'status_code' => $this->getStatusCode(),
'published' => $this->getPublished()
];
}
}