src/Entity/Path.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. /**
  6.  * Class Path.
  7.  */
  8. #[ORM\Table(name'path')]
  9. #[ORM\Entity(repositoryClass\App\Repository\PathRepository::class)]
  10. class Path
  11. {
  12.     final public const TYPE_CURRENT  'current';
  13.     final public const TYPE_REDIRECT 'redirect';
  14.     /**
  15.      * Id.
  16.      */
  17.     #[ORM\Id]
  18.     #[ORM\Column(type\Doctrine\DBAL\Types\Types::INTEGER)]
  19.     #[ORM\GeneratedValue]
  20.     protected int $id;
  21.     /**
  22.      * Type.
  23.      */
  24.     #[ORM\Column(type\Doctrine\DBAL\Types\Types::STRINGlength255)]
  25.     #[Assert\NotBlank(message'form.error.required')]
  26.     #[Assert\Length(min2max255minMessage'form.error.short'maxMessage'form.error.long')]
  27.     protected string $type;
  28.     /**
  29.      * Locale.
  30.      */
  31.     #[ORM\Column(type\Doctrine\DBAL\Types\Types::STRINGlength255)]
  32.     #[Assert\NotBlank(message'form.error.required')]
  33.     protected string $locale 'en';
  34.     /**
  35.      * Path.
  36.      */
  37.     #[ORM\Column(type\Doctrine\DBAL\Types\Types::STRINGlength255)]
  38.     #[Assert\Length(max255maxMessage'form.error.long')]
  39.     #[Assert\Regex(pattern'/^[a-zA-Z0-9-\/]+$/i', match: truemessage'form.error.path')]
  40.     protected string $path;
  41.     /**
  42.      * Master.
  43.      */
  44.     #[ORM\ManyToOne(targetEntity'Page'inversedBy'paths'cascade: ['detach'])]
  45.     #[ORM\JoinColumn(name'page_id')]
  46.     protected ?Page $page null;
  47.     /**
  48.      * Path constructor.
  49.      */
  50.     public function __construct(string $pathstring $localebool $redirect false)
  51.     {
  52.         $this->setPath($path);
  53.         $this->setLocale($locale);
  54.         if ($redirect) {
  55.             $this->setType(Path::TYPE_REDIRECT);
  56.         } else {
  57.             $this->setType(Path::TYPE_CURRENT);
  58.         }
  59.     }
  60.     public function setId(int $id): void
  61.     {
  62.         $this->id $id;
  63.     }
  64.     public function getId(): int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getType(): string
  69.     {
  70.         return $this->type;
  71.     }
  72.     public function setType(string $type): void
  73.     {
  74.         $this->type $type;
  75.     }
  76.     public function getLocale(): string
  77.     {
  78.         return $this->locale;
  79.     }
  80.     public function setLocale(string $locale): void
  81.     {
  82.         $this->locale $locale;
  83.     }
  84.     public function getPath(): string
  85.     {
  86.         return $this->path;
  87.     }
  88.     public function setPath(string $path): void
  89.     {
  90.         $this->path $path;
  91.     }
  92.     public function getPage(): Page
  93.     {
  94.         return $this->page;
  95.     }
  96.     public function setPage(?Page $page): void
  97.     {
  98.         $this->page $page;
  99.     }
  100. }