lib/composer/LisaBundle/src/VisualMedia/LisaBundle/Component/MenuItem.php line 109

Open in your IDE?
  1. <?php
  2. /**
  3. * Menu Item
  4. *
  5. * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  6. */
  7. namespace VisualMedia\LisaBundle\Component;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. use VisualMedia\LisaBundle\Component\Interfaces\MenuItemInterface;
  11. /**
  12. * Menu Item
  13. */
  14. abstract class MenuItem implements MenuItemInterface
  15. {
  16. /**
  17. * Translator
  18. * @var TranslatorInterface
  19. */
  20. protected $translator;
  21. /**
  22. * Router
  23. * @var RouterInterface
  24. */
  25. protected $router;
  26. /**
  27. * Title
  28. * @var string|array
  29. */
  30. protected $title;
  31. /**
  32. * Icon
  33. * @var string
  34. */
  35. protected $icon;
  36. /**
  37. * Path
  38. * @var string|array
  39. */
  40. protected $path = self::PATH_HASH;
  41. /**
  42. * Path Target
  43. * @var string
  44. */
  45. protected $pathTarget;
  46. /**
  47. * Active Regex
  48. * @var string
  49. */
  50. protected $activeRegex;
  51. /**
  52. * Active Singular Regex
  53. * @var string
  54. */
  55. protected $activeSingularRegex;
  56. /**
  57. * Active Route
  58. * @var string
  59. */
  60. protected $activeRoute;
  61. /**
  62. * Active
  63. * @var bool
  64. */
  65. protected $active = false;
  66. /**
  67. * Permission
  68. * @var string
  69. */
  70. protected $permission;
  71. /**
  72. * Parent
  73. * @var string
  74. */
  75. protected $parent;
  76. /**
  77. * Classes
  78. * @var string|array
  79. */
  80. protected $classes;
  81. /**
  82. * Children
  83. * @var array<MenuItemInterface>
  84. */
  85. private $children = array();
  86. /**
  87. * Constructor
  88. *
  89. * @param TranslatorInterface $translator
  90. * @param Router $router
  91. */
  92. public function __construct(TranslatorInterface $translator = null, RouterInterface $router = null)
  93. {
  94. $this->translator = $translator;
  95. $this->router = $router;
  96. }
  97. /**
  98. * Get Title
  99. *
  100. * @return string|Closure
  101. */
  102. public function getTitle()
  103. {
  104. return $this->title;
  105. }
  106. /**
  107. * Set Title
  108. *
  109. * @param string|Closure $title
  110. *
  111. * @return MenuItemInterface
  112. */
  113. public function setTitle($title): MenuItemInterface
  114. {
  115. $this->title = $title;
  116. return $this;
  117. }
  118. /**
  119. * Get Path
  120. *
  121. * @return string
  122. */
  123. public function getPath(): string
  124. {
  125. return $this->path;
  126. }
  127. /**
  128. * Set Path
  129. *
  130. * @param string $path
  131. *
  132. * @return MenuItemInterface
  133. */
  134. public function setPath($path): MenuItemInterface
  135. {
  136. $this->path = $path;
  137. return $this;
  138. }
  139. /**
  140. * Get Path Target
  141. *
  142. * @return string
  143. */
  144. public function getPathTarget(): ?string
  145. {
  146. return $this->pathTarget;
  147. }
  148. /**
  149. * Set Path Target
  150. *
  151. * @param string $path
  152. *
  153. * @return MenuItemInterface
  154. */
  155. public function setPathTarget($pathTarget): MenuItemInterface
  156. {
  157. $this->pathTarget = $pathTarget;
  158. return $this;
  159. }
  160. /**
  161. * Get Icon
  162. *
  163. * @return string
  164. */
  165. public function getIcon(): ?string
  166. {
  167. return $this->icon;
  168. }
  169. /**
  170. * Set Icon
  171. *
  172. * @param string $icon
  173. *
  174. * @return MenuItemInterface
  175. */
  176. public function setIcon($icon): MenuItemInterface
  177. {
  178. $this->icon = $icon;
  179. return $this;
  180. }
  181. /**
  182. * Get Parent
  183. *
  184. * @return string
  185. */
  186. public function getParent(): ?string
  187. {
  188. return $this->parent;
  189. }
  190. /**
  191. * Set Parent
  192. *
  193. * @param string $parent
  194. *
  195. * @return MenuItemInterface
  196. */
  197. public function setParent($parent): MenuItemInterface
  198. {
  199. $this->parent = $parent;
  200. return $this;
  201. }
  202. /**
  203. * Get Active Regex
  204. *
  205. * @return string|array
  206. */
  207. public function getActiveRegex()
  208. {
  209. return $this->activeRegex;
  210. }
  211. /**
  212. * Set Active Regex
  213. *
  214. * @param string|array $activeRegex
  215. *
  216. * @return MenuItemInterface
  217. */
  218. public function setActiveRegex($activeRegex): MenuItemInterface
  219. {
  220. $this->activeRegex = $activeRegex;
  221. return $this;
  222. }
  223. /**
  224. * Get Active Singular Regex
  225. *
  226. * @return string|array
  227. */
  228. public function getSingularActiveRegex()
  229. {
  230. return $this->activeSingularRegex;
  231. }
  232. /**
  233. * Set Active Singular Regex
  234. *
  235. * @param string|array $activeSingularRegex
  236. *
  237. * @return MenuItemInterface
  238. */
  239. public function setActiveSingularRegex($activeSingularRegex): MenuItemInterface
  240. {
  241. $this->activeSingularRegex = $activeSingularRegex;
  242. return $this;
  243. }
  244. /**
  245. * Get Active Route
  246. *
  247. * @return string
  248. */
  249. public function getActiveRoute(): ?string
  250. {
  251. return $this->activeRoute;
  252. }
  253. /**
  254. * Set Active Route
  255. *
  256. * @param string $activeRoute
  257. *
  258. * @return MenuItemInterface
  259. */
  260. public function setActiveRoute($activeRoute): MenuItemInterface
  261. {
  262. $this->activeRoute = $activeRoute;
  263. return $this;
  264. }
  265. /**
  266. * Get Active
  267. *
  268. * @return bool
  269. */
  270. public function getActive(): bool
  271. {
  272. return $this->active;
  273. }
  274. /**
  275. * Set Active
  276. *
  277. * @param bool $active
  278. *
  279. * @return MenuItemInterface
  280. */
  281. public function setActive($active): MenuItemInterface
  282. {
  283. $this->active = $active;
  284. return $this;
  285. }
  286. /**
  287. * Get Permission
  288. *
  289. * @return string
  290. */
  291. public function getPermission(): ?string
  292. {
  293. return $this->permission;
  294. }
  295. /**
  296. * Set Permission
  297. *
  298. * @param string $permission
  299. *
  300. * @return MenuItemInterface
  301. */
  302. public function setPermission($permission): MenuItemInterface
  303. {
  304. $this->permission = $permission;
  305. return $this;
  306. }
  307. /**
  308. * Add Child
  309. *
  310. * @param MenuItemInterface $child
  311. *
  312. * @return MenuItemInterface
  313. */
  314. public function addChild(MenuItemInterface $child): MenuItemInterface
  315. {
  316. $this->children[$child->getKey()] = $child;
  317. return $this;
  318. }
  319. /**
  320. * Get Classes
  321. *
  322. * @return array|null
  323. */
  324. public function getClasses(): ?array
  325. {
  326. if(!is_array($this->classes)) {
  327. return array($this->classes);
  328. }
  329. return $this->classes;
  330. }
  331. /**
  332. * Set Classes
  333. *
  334. * @param array|string $classes
  335. */
  336. public function setClasses($classes): void
  337. {
  338. if(!is_array($classes)){
  339. $classes = array($classes);
  340. }
  341. $this->classes = $classes;
  342. }
  343. /**
  344. * Get Children
  345. *
  346. * @return array
  347. */
  348. public function getChildren(): array
  349. {
  350. return $this->children;
  351. }
  352. /**
  353. * Set Children
  354. *
  355. * @param array $children
  356. *
  357. * @return MenuItemInterface
  358. */
  359. public function setChildren(array $children): MenuItemInterface
  360. {
  361. $this->children = $children;
  362. return $this;
  363. }
  364. }