* @category Community Framework
*/
abstract class TreeMenu extends SingletonFactory {
+ /**
+ * @var EventHandler
+ */
+ protected $eventHandler;
+
/**
* list of visible menu items
* @var array<\wcf\system\menu\ITreeMenuItem>
*/
public $menuItems = null;
+ /**
+ * TreeMenu constructor.
+ *
+ * @param EventHandler $eventHandler
+ */
+ public function __construct(EventHandler $eventHandler) {
+ $this->eventHandler = $eventHandler;
+
+ parent::__construct();
+ }
+
/**
* @see \wcf\system\SingletonFactory::init()
*/
$this->buildMenuItemList();
// call init event
- EventHandler::getInstance()->fireAction($this, 'init');
+ $this->eventHandler->fireAction($this, 'init');
}
/**
*/
protected function loadCache() {
// call loadCache event
- EventHandler::getInstance()->fireAction($this, 'loadCache');
+ $this->eventHandler->fireAction($this, 'loadCache');
$this->menuItems = array();
}
$newActiveMenuItems[] = $menuItem;
$menuItem = $this->menuItemList[$menuItem]->parentMenuItem;
- if ($menuItem && !isset($this->menuItemList[$menuItem])) return false;
+ if ($menuItem && !isset($this->menuItemList[$menuItem])) return;
}
if (!empty($newActiveMenuItems)) $this->activeMenuItems = $newActiveMenuItems;
<?php
namespace wcf\system\menu\acp;
use wcf\system\cache\builder\ACPMenuCacheBuilder;
+use wcf\system\event\EventHandler;
use wcf\system\menu\TreeMenu;
/**
*/
class ACPMenu extends TreeMenu {
/**
- * @see \wcf\system\menu\TreeMenu::loadCache()
+ * @var ACPMenuCacheBuilder
+ */
+ protected $acpMenuCacheBuilder;
+
+ /**
+ * ACPMenu constructor.
+ *
+ * @param ACPMenuCacheBuilder $acpMenuCacheBuilder
+ * @param EventHandler $eventHandler
+ */
+ public function __construct(ACPMenuCacheBuilder $acpMenuCacheBuilder, EventHandler $eventHandler) {
+ $this->acpMenuCacheBuilder = $acpMenuCacheBuilder;
+
+ parent::__construct($eventHandler);
+ }
+
+ /**
+ * @see TreeMenu::loadCache()
*/
protected function loadCache() {
parent::loadCache();
return;
}
- $this->menuItems = ACPMenuCacheBuilder::getInstance()->getData();
+ $this->menuItems = $this->acpMenuCacheBuilder->getData();
}
}
<?php
namespace wcf\system\menu\page;
+use wcf\data\ProcessibleDatabaseObject;
use wcf\system\cache\builder\PageMenuCacheBuilder;
use wcf\system\event\EventHandler;
use wcf\system\exception\SystemException;
*/
protected $landingPage = null;
+ /**
+ * @var PageMenuCacheBuilder
+ */
+ protected $pageMenuCacheBuilder;
+
+ /**
+ * PageMenu constructor.
+ *
+ * @param EventHandler $eventHandler
+ * @param PageMenuCacheBuilder $pageMenuCacheBuilder
+ */
+ public function __construct(EventHandler $eventHandler, PageMenuCacheBuilder $pageMenuCacheBuilder) {
+ $this->pageMenuCacheBuilder = $pageMenuCacheBuilder;
+
+ parent::__construct($eventHandler);
+ }
+
/**
* @see \wcf\system\SingletonFactory::init()
+ * @throws SystemException
*/
protected function init() {
// get menu items from cache
$this->buildMenuItemList('footer');
// call init event
- EventHandler::getInstance()->fireAction($this, 'init');
+ $this->eventHandler->fireAction($this, 'init');
foreach ($this->menuItems as $menuItems) {
foreach ($menuItems as $menuItem) {
parent::loadCache();
// get cache
- $this->menuItems = PageMenuCacheBuilder::getInstance()->getData();
+ $this->menuItems = $this->pageMenuCacheBuilder->getData();
}
/**
if (!parent::checkMenuItem($item)) return false;
- return $item->getProcessor()->isVisible();
+ if ($item instanceof ProcessibleDatabaseObject && $item->getProcessor() instanceof IPageMenuItemProvider) {
+ return $item->getProcessor()->isVisible();
+ }
+
+ return true;
}
/**
<?php
namespace wcf\system\menu\user;
+use wcf\data\ProcessibleDatabaseObject;
use wcf\system\cache\builder\UserMenuCacheBuilder;
+use wcf\system\event\EventHandler;
use wcf\system\menu\ITreeMenuItem;
+use wcf\system\menu\page\IPageMenuItemProvider;
use wcf\system\menu\TreeMenu;
/**
*/
class UserMenu extends TreeMenu {
/**
- * @see \wcf\system\menu\TreeMenu::loadCache()
+ * @var UserMenuCacheBuilder
+ */
+ protected $userMenuCacheBuilder;
+
+ /**
+ * UserMenu constructor.
+ *
+ * @param EventHandler $eventHandler
+ * @param UserMenuCacheBuilder $userMenuCacheBuilder
+ */
+ public function __construct(EventHandler $eventHandler, UserMenuCacheBuilder $userMenuCacheBuilder) {
+ $this->userMenuCacheBuilder = $userMenuCacheBuilder;
+
+ parent::__construct($eventHandler);
+ }
+
+ /**
+ * @see TreeMenu::loadCache()
*/
protected function loadCache() {
parent::loadCache();
- $this->menuItems = UserMenuCacheBuilder::getInstance()->getData();
+ $this->menuItems = $this->userMenuCacheBuilder->getData();
}
/**
- * @see \wcf\system\menu\TreeMenu::checkMenuItem()
+ * @see TreeMenu::checkMenuItem()
*/
protected function checkMenuItem(ITreeMenuItem $item) {
if (!parent::checkMenuItem($item)) return false;
- return $item->getProcessor()->isVisible();
+ if ($item instanceof ProcessibleDatabaseObject && $item->getProcessor() instanceof IPageMenuItemProvider) {
+ return $item->getProcessor()->isVisible();
+ }
+
+ return true;
}
}
* @category Community Framework
*/
class UserProfileMenu extends SingletonFactory {
+ /**
+ * active menu item
+ * @var UserProfileMenuItem
+ */
+ public $activeMenuItem = null;
+
+ /**
+ * @var EventHandler
+ */
+ protected $eventHandler;
+
/**
* list of all menu items
- * @var array<\wcf\data\user\profile\menu\item\UserProfileMenuItem>
+ * @var UserProfileMenuItem[]
*/
public $menuItems = null;
/**
- * active menu item
- * @var \wcf\data\user\profile\menu\item\UserProfileMenuItem
+ * @var UserProfileMenuCacheBuilder
*/
- public $activeMenuItem = null;
+ protected $userProfileMenuCacheBuilder;
+
+ /**
+ * UserProfileMenu constructor.
+ *
+ * @param EventHandler $eventHandler
+ * @param UserProfileMenuCacheBuilder $userProfileMenuCacheBuilder
+ */
+ public function __construct(EventHandler $eventHandler, UserProfileMenuCacheBuilder $userProfileMenuCacheBuilder) {
+ $this->eventHandler = $eventHandler;
+ $this->userProfileMenuCacheBuilder = $userProfileMenuCacheBuilder;
+
+ parent::__construct();
+ }
/**
* @see \wcf\system\SingletonFactory::init()
$this->checkMenuItems();
// call init event
- EventHandler::getInstance()->fireAction($this, 'init');
+ $this->eventHandler->fireAction($this, 'init');
}
/**
*/
protected function loadCache() {
// call loadCache event
- EventHandler::getInstance()->fireAction($this, 'loadCache');
+ $this->eventHandler->fireAction($this, 'loadCache');
- $this->menuItems = UserProfileMenuCacheBuilder::getInstance()->getData();
+ $this->menuItems = $this->userProfileMenuCacheBuilder->getData();
}
/**
/**
* Checks the options and permissions of given menu item.
*
- * @param \wcf\data\user\profile\menu\item\UserProfileMenuItem $item
+ * @param UserProfileMenuItem $item
* @return boolean
*/
protected function checkMenuItem(UserProfileMenuItem $item) {
/**
* Returns the list of menu items.
*
- * @return array<\wcf\data\user\profile\menu\item\UserProfileMenuItem>
+ * @return UserProfileMenuItem[]
*/
public function getMenuItems() {
return $this->menuItems;
/**
* Returns the first menu item.
*
- * @return \wcf\data\user\profile\menu\item\UserProfileMenuItem
+ * @return UserProfileMenuItem
*/
public function getActiveMenuItem() {
if (empty($this->menuItems)) {
/**
* Returns a specific menu item.
*
- * @return \wcf\data\user\profile\menu\item\UserProfileMenuItem
+ * @return UserProfileMenuItem
*/
public function getMenuItem($menuItem) {
foreach ($this->menuItems as $item) {
return;
}
- $landingPage = PageMenu::getInstance()->getLandingPage();
+ $landingPage = WCF::getDIContainer()->get(PageMenu::class)->getLandingPage();
if ($landingPage === null) {
return;
}
// check if currently invoked application matches the landing page
if ($landingPageApplication == $application) {
$routeData['controller'] = $landingPage->getController();
- $routeData['controller'] = $this->getControllerMap()->lookup($routeData['controller']);
+ $routeData['controller'] = $this->controllerMap->lookup($routeData['controller']);
return;
}
// set default controller
$applicationObj = WCF::getApplicationObject($this->applicationHandler->getApplication($application));
$routeData['controller'] = preg_replace('~^.*?\\\([^\\\]+)(?:Action|Form|Page)$~', '\\1', $applicationObj->getPrimaryController());
- $routeData['controller'] = $this->getControllerMap()->lookup($routeData['controller']);
+ $routeData['controller'] = $this->controllerMap->lookup($routeData['controller']);
}
/**
public function inRescueMode() {
return $this->inRescueMode;
}
-
- /**
- * Returns the controller map instance.
- *
- * @return \wcf\system\request\ControllerMap
- */
- public function getControllerMap() {
- return $this->controllerMap;
- }
}
namespace wcf\system\request\route;
use wcf\system\application\ApplicationHandler;
use wcf\system\menu\page\PageMenu;
+use wcf\system\request\ControllerMap;
use wcf\system\request\RequestHandler;
use wcf\system\request\RouteHandler;
*/
protected $buildSchema = [];
+ /**
+ * @var ControllerMap
+ */
+ protected $controllerMap;
+
/**
* route is restricted to ACP
* @var boolean
* DynamicRequestRoute constructor.
*
* @param ApplicationHandler $applicationHandler
+ * @param ControllerMap $controllerMap
* @param PageMenu $pageMenu
* @param RequestHandler $requestHandler
* @param RouteHandler $routeHandler
*/
- public function __construct(ApplicationHandler $applicationHandler, PageMenu $pageMenu, RequestHandler $requestHandler, RouteHandler $routeHandler) {
+ public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, PageMenu $pageMenu, RequestHandler $requestHandler, RouteHandler $routeHandler) {
$this->applicationHandler = $applicationHandler;
+ $this->controllerMap = $controllerMap;
$this->pageMenu = $pageMenu;
$this->requestHandler = $requestHandler;
$this->routeHandler = $routeHandler;
* @return string
*/
protected function getControllerName($application, $controller) {
- return RequestHandler::getInstance()->getControllerMap()->lookup($controller);
+ return $this->controllerMap->lookup($controller);
}
}