<?php/** * Menu Item * * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl> */namespace VisualMedia\LisaBundle\Component;use Symfony\Component\Routing\RouterInterface;use Symfony\Contracts\Translation\TranslatorInterface;use VisualMedia\LisaBundle\Component\Interfaces\MenuItemInterface;/** * Menu Item */abstract class MenuItem implements MenuItemInterface{ /** * Translator * @var TranslatorInterface */ protected $translator; /** * Router * @var RouterInterface */ protected $router; /** * Title * @var string|array */ protected $title; /** * Icon * @var string */ protected $icon; /** * Path * @var string|array */ protected $path = self::PATH_HASH; /** * Path Target * @var string */ protected $pathTarget; /** * Active Regex * @var string */ protected $activeRegex; /** * Active Singular Regex * @var string */ protected $activeSingularRegex; /** * Active Route * @var string */ protected $activeRoute; /** * Active * @var bool */ protected $active = false; /** * Permission * @var string */ protected $permission; /** * Parent * @var string */ protected $parent; /** * Classes * @var string|array */ protected $classes; /** * Children * @var array<MenuItemInterface> */ private $children = array(); /** * Constructor * * @param TranslatorInterface $translator * @param Router $router */ public function __construct(TranslatorInterface $translator = null, RouterInterface $router = null) { $this->translator = $translator; $this->router = $router; } /** * Get Title * * @return string|Closure */ public function getTitle() { return $this->title; } /** * Set Title * * @param string|Closure $title * * @return MenuItemInterface */ public function setTitle($title): MenuItemInterface { $this->title = $title; return $this; } /** * Get Path * * @return string */ public function getPath(): string { return $this->path; } /** * Set Path * * @param string $path * * @return MenuItemInterface */ public function setPath($path): MenuItemInterface { $this->path = $path; return $this; } /** * Get Path Target * * @return string */ public function getPathTarget(): ?string { return $this->pathTarget; } /** * Set Path Target * * @param string $path * * @return MenuItemInterface */ public function setPathTarget($pathTarget): MenuItemInterface { $this->pathTarget = $pathTarget; return $this; } /** * Get Icon * * @return string */ public function getIcon(): ?string { return $this->icon; } /** * Set Icon * * @param string $icon * * @return MenuItemInterface */ public function setIcon($icon): MenuItemInterface { $this->icon = $icon; return $this; } /** * Get Parent * * @return string */ public function getParent(): ?string { return $this->parent; } /** * Set Parent * * @param string $parent * * @return MenuItemInterface */ public function setParent($parent): MenuItemInterface { $this->parent = $parent; return $this; } /** * Get Active Regex * * @return string|array */ public function getActiveRegex() { return $this->activeRegex; } /** * Set Active Regex * * @param string|array $activeRegex * * @return MenuItemInterface */ public function setActiveRegex($activeRegex): MenuItemInterface { $this->activeRegex = $activeRegex; return $this; } /** * Get Active Singular Regex * * @return string|array */ public function getSingularActiveRegex() { return $this->activeSingularRegex; } /** * Set Active Singular Regex * * @param string|array $activeSingularRegex * * @return MenuItemInterface */ public function setActiveSingularRegex($activeSingularRegex): MenuItemInterface { $this->activeSingularRegex = $activeSingularRegex; return $this; } /** * Get Active Route * * @return string */ public function getActiveRoute(): ?string { return $this->activeRoute; } /** * Set Active Route * * @param string $activeRoute * * @return MenuItemInterface */ public function setActiveRoute($activeRoute): MenuItemInterface { $this->activeRoute = $activeRoute; return $this; } /** * Get Active * * @return bool */ public function getActive(): bool { return $this->active; } /** * Set Active * * @param bool $active * * @return MenuItemInterface */ public function setActive($active): MenuItemInterface { $this->active = $active; return $this; } /** * Get Permission * * @return string */ public function getPermission(): ?string { return $this->permission; } /** * Set Permission * * @param string $permission * * @return MenuItemInterface */ public function setPermission($permission): MenuItemInterface { $this->permission = $permission; return $this; } /** * Add Child * * @param MenuItemInterface $child * * @return MenuItemInterface */ public function addChild(MenuItemInterface $child): MenuItemInterface { $this->children[$child->getKey()] = $child; return $this; } /** * Get Classes * * @return array|null */ public function getClasses(): ?array { if(!is_array($this->classes)) { return array($this->classes); } return $this->classes; } /** * Set Classes * * @param array|string $classes */ public function setClasses($classes): void { if(!is_array($classes)){ $classes = array($classes); } $this->classes = $classes; } /** * Get Children * * @return array */ public function getChildren(): array { return $this->children; } /** * Set Children * * @param array $children * * @return MenuItemInterface */ public function setChildren(array $children): MenuItemInterface { $this->children = $children; return $this; }}