<?php
namespace App\Entity\Routing;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
use Symfony\Component\Validator\Constraints as Assert;
use WAM\Bundle\BlockBundle\Entity\UrlHasBlocks;
use WAM\Bundle\BlockBundle\Model\AttributableInterface;
use WAM\Bundle\BlockBundle\Model\Traits\AttributableTrait;
use WAM\Bundle\CoreBundle\Entity\Interfaces\IdentifiableInterface;
use WAM\Bundle\CoreBundle\Model\Identifiable;
use WAM\Bundle\CoreBundle\Model\Translatable;
use WAM\Bundle\CoreBundle\Validator\Constraints as wam;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\HostInterface;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\SeoBehaviourInterface;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\UrlInterface;
use WAM\Bundle\RoutingBundle\Entity\Traits\MultiRouteTrait;
/**
* @ORM\Entity()
* @UniqueEntity("name")
* @ORM\Table(name="app_routing_url")
*
**/
class Url implements TranslatableInterface, IdentifiableInterface, AttributableInterface, RouteReferrersInterface, SeoBehaviourInterface, UrlInterface
{
use Identifiable;
use MultiRouteTrait;
use AttributableTrait;
use Translatable;
/**
* @ORM\Column(type="string", length=50, unique=true)
* @Assert\NotBlank()
*
* @var string
*/
private ?string $name = null;
/**
* @ORM\Column(type="string", nullable=true)
* @wam\ControllerExists()
*
* @var string
*/
private ?string $controller = null;
/**
* @ORM\Column(type="string", nullable=true)
* @wam\TemplateExists()
*
* @var string
*/
private ?string $template = null;
/**
* @ORM\OneToMany(targetEntity="WAM\Bundle\BlockBundle\Entity\UrlHasBlocks", mappedBy="url", orphanRemoval=true, cascade={"persist"})
* @ORM\OrderBy({"position" = "ASC"})
*/
protected Collection $urlHasBlocks;
/**
* @ORM\ManyToOne(targetEntity="WAM\Bundle\RoutingBundle\Entity\Host")
**/
private ?Host $host = null;
public function __construct()
{
$this->urlHasBlocks = new ArrayCollection();
}
/**
* @return string
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return Url
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getController(): ?string
{
return $this->controller;
}
/**
* @param string $controller
* @return Url
*/
public function setController(?string $controller): self
{
$this->controller = $controller;
return $this;
}
/**
* @return string
*/
public function getTemplate(): ?string
{
return $this->template;
}
/**
* @param string $template
* @return Url
*/
public function setTemplate(?string $template): self
{
$this->template = $template;
return $this;
}
/**
* @return ArrayCollection|Collection
*/
public function getUrlHasBlocks(): Collection
{
return $this->urlHasBlocks;
}
/**
* @param ArrayCollection|Collection $urlHasBlocks
* @return Url
*/
public function setUrlHasBlocks(Collection $urlHasBlocks): self
{
$this->urlHasBlocks = $urlHasBlocks;
return $this;
}
public function getPath(): string
{
return $this->translate(null, false)->getPath();
}
public function setPath(string $path): self
{
$this->translate(null, false)->setPath($path);
return $this;
}
public function addUrlHasBlocks(UrlHasBlocks $urlHasBlocks): self
{
if (!$this->urlHasBlocks->contains($urlHasBlocks)) {
$this->urlHasBlocks->add($urlHasBlocks);
}
return $this;
}
/**
* @return Host|null
*/
public function getHost(): ?HostInterface
{
return $this->host;
}
/**
* @param Host|null $host
* @return Url
*/
public function setHost(HostInterface $host): self
{
$this->host = $host;
return $this;
}
public function __toString()
{
return (string) $this->getName();
}
}