From: Alexander Ebert Date: Wed, 18 Nov 2015 14:01:30 +0000 (+0100) Subject: Some fixes and minor overhauls X-Git-Tag: 3.0.0_Beta_1~2030^2~243 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4149fdb24c8bd2ccd200e30267f591db246cc04c;p=GitHub%2FWoltLab%2FWCF.git Some fixes and minor overhauls --- diff --git a/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php b/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php index dd80b4b59c..0e52537f23 100644 --- a/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php @@ -15,6 +15,11 @@ use wcf\system\WCF; * @category Community Framework */ abstract class TreeMenu extends SingletonFactory { + /** + * @var EventHandler + */ + protected $eventHandler; + /** * list of visible menu items * @var array<\wcf\system\menu\ITreeMenuItem> @@ -33,6 +38,17 @@ abstract class TreeMenu extends SingletonFactory { */ public $menuItems = null; + /** + * TreeMenu constructor. + * + * @param EventHandler $eventHandler + */ + public function __construct(EventHandler $eventHandler) { + $this->eventHandler = $eventHandler; + + parent::__construct(); + } + /** * @see \wcf\system\SingletonFactory::init() */ @@ -50,7 +66,7 @@ abstract class TreeMenu extends SingletonFactory { $this->buildMenuItemList(); // call init event - EventHandler::getInstance()->fireAction($this, 'init'); + $this->eventHandler->fireAction($this, 'init'); } /** @@ -58,7 +74,7 @@ abstract class TreeMenu extends SingletonFactory { */ protected function loadCache() { // call loadCache event - EventHandler::getInstance()->fireAction($this, 'loadCache'); + $this->eventHandler->fireAction($this, 'loadCache'); $this->menuItems = array(); } @@ -166,7 +182,7 @@ abstract class TreeMenu extends SingletonFactory { $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; diff --git a/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php b/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php index e4005c95f3..a828e0af8b 100644 --- a/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php @@ -1,6 +1,7 @@ acpMenuCacheBuilder = $acpMenuCacheBuilder; + + parent::__construct($eventHandler); + } + + /** + * @see TreeMenu::loadCache() */ protected function loadCache() { parent::loadCache(); @@ -24,6 +42,6 @@ class ACPMenu extends TreeMenu { return; } - $this->menuItems = ACPMenuCacheBuilder::getInstance()->getData(); + $this->menuItems = $this->acpMenuCacheBuilder->getData(); } } diff --git a/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php b/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php index 66c6bcce92..ba95c43adc 100644 --- a/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php @@ -1,5 +1,6 @@ pageMenuCacheBuilder = $pageMenuCacheBuilder; + + parent::__construct($eventHandler); + } + /** * @see \wcf\system\SingletonFactory::init() + * @throws SystemException */ protected function init() { // get menu items from cache @@ -39,7 +58,7 @@ class PageMenu extends TreeMenu { $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) { @@ -73,7 +92,7 @@ class PageMenu extends TreeMenu { parent::loadCache(); // get cache - $this->menuItems = PageMenuCacheBuilder::getInstance()->getData(); + $this->menuItems = $this->pageMenuCacheBuilder->getData(); } /** @@ -87,7 +106,11 @@ class PageMenu extends TreeMenu { if (!parent::checkMenuItem($item)) return false; - return $item->getProcessor()->isVisible(); + if ($item instanceof ProcessibleDatabaseObject && $item->getProcessor() instanceof IPageMenuItemProvider) { + return $item->getProcessor()->isVisible(); + } + + return true; } /** diff --git a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php index 592028c538..e2a3305794 100644 --- a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php @@ -1,7 +1,10 @@ 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; } } diff --git a/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php index 55a94a23b6..c6f56507e4 100644 --- a/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php @@ -17,17 +17,40 @@ use wcf\system\WCF; * @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() @@ -40,7 +63,7 @@ class UserProfileMenu extends SingletonFactory { $this->checkMenuItems(); // call init event - EventHandler::getInstance()->fireAction($this, 'init'); + $this->eventHandler->fireAction($this, 'init'); } /** @@ -48,9 +71,9 @@ class UserProfileMenu extends SingletonFactory { */ 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(); } /** @@ -68,7 +91,7 @@ class UserProfileMenu extends SingletonFactory { /** * 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) { @@ -78,7 +101,7 @@ class UserProfileMenu extends SingletonFactory { /** * Returns the list of menu items. * - * @return array<\wcf\data\user\profile\menu\item\UserProfileMenuItem> + * @return UserProfileMenuItem[] */ public function getMenuItems() { return $this->menuItems; @@ -104,7 +127,7 @@ class UserProfileMenu extends SingletonFactory { /** * Returns the first menu item. * - * @return \wcf\data\user\profile\menu\item\UserProfileMenuItem + * @return UserProfileMenuItem */ public function getActiveMenuItem() { if (empty($this->menuItems)) { @@ -122,7 +145,7 @@ class UserProfileMenu extends SingletonFactory { /** * Returns a specific menu item. * - * @return \wcf\data\user\profile\menu\item\UserProfileMenuItem + * @return UserProfileMenuItem */ public function getMenuItem($menuItem) { foreach ($this->menuItems as $item) { diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 457cc89807..137f16c171 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -267,7 +267,7 @@ class RequestHandler extends SingletonFactory { return; } - $landingPage = PageMenu::getInstance()->getLandingPage(); + $landingPage = WCF::getDIContainer()->get(PageMenu::class)->getLandingPage(); if ($landingPage === null) { return; } @@ -285,7 +285,7 @@ class RequestHandler extends SingletonFactory { // 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; } @@ -299,7 +299,7 @@ class RequestHandler extends SingletonFactory { // 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']); } /** @@ -328,13 +328,4 @@ class RequestHandler extends SingletonFactory { public function inRescueMode() { return $this->inRescueMode; } - - /** - * Returns the controller map instance. - * - * @return \wcf\system\request\ControllerMap - */ - public function getControllerMap() { - return $this->controllerMap; - } } diff --git a/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php index 389f37a475..7b20a0113a 100644 --- a/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php @@ -2,6 +2,7 @@ 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; @@ -27,6 +28,11 @@ class DynamicRequestRoute implements IRequestRoute { */ protected $buildSchema = []; + /** + * @var ControllerMap + */ + protected $controllerMap; + /** * route is restricted to ACP * @var boolean @@ -76,12 +82,14 @@ class DynamicRequestRoute implements IRequestRoute { * 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; @@ -344,6 +352,6 @@ class DynamicRequestRoute implements IRequestRoute { * @return string */ protected function getControllerName($application, $controller) { - return RequestHandler::getInstance()->getControllerMap()->lookup($controller); + return $this->controllerMap->lookup($controller); } }