Some fixes and minor overhauls
authorAlexander Ebert <ebert@woltlab.com>
Wed, 18 Nov 2015 14:01:30 +0000 (15:01 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 18 Nov 2015 14:01:30 +0000 (15:01 +0100)
wcfsetup/install/files/lib/system/menu/TreeMenu.class.php
wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php
wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php
wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php
wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php
wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php

index dd80b4b59c0b75cde826a3b9aca06cf27c76b0d8..0e52537f23b9dd1de3f5e60c1d07b6d467bd064a 100644 (file)
@@ -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;
index e4005c95f35311b6a99df0845246933b307b57a0..a828e0af8bfe26eaa3508449db41b798c4d06c36 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\menu\acp;
 use wcf\system\cache\builder\ACPMenuCacheBuilder;
+use wcf\system\event\EventHandler;
 use wcf\system\menu\TreeMenu;
 
 /**
@@ -15,7 +16,24 @@ 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();
@@ -24,6 +42,6 @@ class ACPMenu extends TreeMenu {
                        return;
                }
                
-               $this->menuItems = ACPMenuCacheBuilder::getInstance()->getData();
+               $this->menuItems = $this->acpMenuCacheBuilder->getData();
        }
 }
index 66c6bcce92af440f6ec34017031c083e6de184b1..ba95c43adc73835032bb86f4885d54348e209273 100644 (file)
@@ -1,5 +1,6 @@
 <?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;
@@ -23,8 +24,26 @@ class PageMenu extends TreeMenu {
         */
        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
@@ -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;
        }
        
        /**
index 592028c53886bb7573f9222b2798b8b9e6409e2b..e2a33057940aad62d83d30e5b79a6cc77b58adb2 100644 (file)
@@ -1,7 +1,10 @@
 <?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;
 
 /**
@@ -16,20 +19,41 @@ 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;
        }
 }
index 55a94a23b6ce12934cab982ccdd47eebef9d68dc..c6f56507e43ff90876cd5a3ccb5acfc627b2b001 100644 (file)
@@ -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) {
index 457cc89807a779fef39e449569c1e06de314876a..137f16c171e5e0832e33df8ac9b1cef11d248697 100644 (file)
@@ -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;
-       }
 }
index 389f37a475bf66f33782787993b283d0538799a7..7b20a0113a27d1b2db95ab2045e94584661ea625 100644 (file)
@@ -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);
        }
 }