<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Path.
*/
#[ORM\Table(name: 'path')]
#[ORM\Entity(repositoryClass: \App\Repository\PathRepository::class)]
class Path
{
final public const TYPE_CURRENT = 'current';
final public const TYPE_REDIRECT = 'redirect';
/**
* Id.
*/
#[ORM\Id]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
#[ORM\GeneratedValue]
protected int $id;
/**
* Type.
*/
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
#[Assert\NotBlank(message: 'form.error.required')]
#[Assert\Length(min: 2, max: 255, minMessage: 'form.error.short', maxMessage: 'form.error.long')]
protected string $type;
/**
* Locale.
*/
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
#[Assert\NotBlank(message: 'form.error.required')]
protected string $locale = 'en';
/**
* Path.
*/
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
#[Assert\Length(max: 255, maxMessage: 'form.error.long')]
#[Assert\Regex(pattern: '/^[a-zA-Z0-9-\/]+$/i', match: true, message: 'form.error.path')]
protected string $path;
/**
* Master.
*/
#[ORM\ManyToOne(targetEntity: 'Page', inversedBy: 'paths', cascade: ['detach'])]
#[ORM\JoinColumn(name: 'page_id')]
protected ?Page $page = null;
/**
* Path constructor.
*/
public function __construct(string $path, string $locale, bool $redirect = false)
{
$this->setPath($path);
$this->setLocale($locale);
if ($redirect) {
$this->setType(Path::TYPE_REDIRECT);
} else {
$this->setType(Path::TYPE_CURRENT);
}
}
public function setId(int $id): void
{
$this->id = $id;
}
public function getId(): int
{
return $this->id;
}
public function getType(): string
{
return $this->type;
}
public function setType(string $type): void
{
$this->type = $type;
}
public function getLocale(): string
{
return $this->locale;
}
public function setLocale(string $locale): void
{
$this->locale = $locale;
}
public function getPath(): string
{
return $this->path;
}
public function setPath(string $path): void
{
$this->path = $path;
}
public function getPage(): Page
{
return $this->page;
}
public function setPage(?Page $page): void
{
$this->page = $page;
}
}