Merge branch '3.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / menu / MenuCache.class.php
CommitLineData
39abe192
AE
1<?php
2namespace wcf\data\menu;
86dbae33 3use wcf\data\menu\item\MenuItemList;
39abe192
AE
4use wcf\system\cache\builder\MenuCacheBuilder;
5use wcf\system\SingletonFactory;
6
7/**
8 * Manages the menu cache.
9 *
10 * @author Alexander Ebert
c839bd49 11 * @copyright 2001-2018 WoltLab GmbH
39abe192 12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4
MW
13 * @package WoltLabSuite\Core\Data\Menu
14 * @since 3.0
39abe192
AE
15 */
16class MenuCache extends SingletonFactory {
17 /**
893aace3 18 * @var Menu[]
39abe192
AE
19 */
20 protected $cachedMenus;
21
22 /**
893aace3 23 * @var MenuItemList[]
39abe192
AE
24 */
25 protected $cachedMenuItems;
26
27 /**
28 * @inheritDoc
29 */
30 protected function init() {
31 $this->cachedMenus = MenuCacheBuilder::getInstance()->getData([], 'menus');
32 $this->cachedMenuItems = MenuCacheBuilder::getInstance()->getData([], 'menuItems');
33 }
34
86dbae33
AE
35 /**
36 * Returns a menu by id.
37 *
893aace3
MS
38 * @param integer $menuID menu id
39 * @return Menu|null menu object or null if menu id is unknown
86dbae33 40 */
39abe192
AE
41 public function getMenuByID($menuID) {
42 if (isset($this->cachedMenus[$menuID])) {
43 return $this->cachedMenus[$menuID];
44 }
45
46 return null;
47 }
48
86dbae33
AE
49 /**
50 * Returns a menu item list by menu id.
51 *
893aace3
MS
52 * @param integer $menuID menu id
53 * @return MenuItemList|null menu item list object or null if menu id is unknown
86dbae33 54 */
39abe192
AE
55 public function getMenuItemsByMenuID($menuID) {
56 if (isset($this->cachedMenuItems[$menuID])) {
57 return $this->cachedMenuItems[$menuID];
58 }
59
60 return null;
61 }
9d5c75df
AE
62
63 /**
64 * Returns the main menu or null.
65 *
8ff2cd79 66 * @return Menu|null menu object
9d5c75df
AE
67 */
68 public function getMainMenu() {
e142deeb
MW
69 return $this->getMenuByID($this->getMainMenuID());
70 }
71
72 /**
73 * Returns the id of the main menu.
74 *
75 * @return integer
76 */
77 public function getMainMenuID() {
78 return MenuCacheBuilder::getInstance()->getData([], 'mainMenuID');
9d5c75df 79 }
39abe192 80}