<?php
namespace WAM\Bundle\RoutingBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface as CmfAutoRouteInterface;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\AutoRouteInterface;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\RouteInterface;
/**
* WAMCMS ORM route.
*
* @ORM\Entity()
*
* @ORM\EntityListeners({"WAM\Bundle\RoutingBundle\Listener\AutoRouteListener"})
*
* @author Noel Garcia <ngarcia@wearemarketing.com>
*/
class AutoRoute extends Route implements CmfAutoRouteInterface, AutoRouteInterface
{
const CONTENT_CLASS_KEY = 'contentClass';
const CONTENT_ID_KEY = 'contentId';
/**
* @ORM\Column(type="string", nullable=true)
*
* @var string
*/
private ?string $contentClass = null;
/**
* @ORM\Column(type="json_array", nullable=true)
*
* @var array
*/
private array $contentId = [];
/**
* @ORM\Column(type="string", nullable=true)
*
* @var string
*/
private ?string $redirectTarget = null;
public function setAutoRouteTag(string $tag): self
{
$this->tag = $tag;
return $this;
}
/**
* {@inheritdoc}
*/
public function setRedirectTarget($autoTarget)
{
if ($autoTarget instanceof RouteInterface) {
$this->redirectTarget = $autoTarget->getName();
} elseif (is_string($autoTarget)) {
$this->redirectTarget = $autoTarget;
} else {
throw new \InvalidArgumentException('Redirect target must be string or auto route');
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getRedirectTarget()
{
return $this->redirectTarget;
}
public function getContentClass(): ?string
{
return $this->contentClass;
}
public function setContentClass(string $class): self
{
$this->contentClass = $class;
return $this;
}
public function getContentId(): array
{
return $this->contentId;
}
public function setContentId(array $id): self
{
$this->contentId = $id;
return $this;
}
}