Updated LinkHandler to use DI
authorAlexander Ebert <ebert@woltlab.com>
Wed, 18 Nov 2015 10:06:37 +0000 (11:06 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 18 Nov 2015 10:06:37 +0000 (11:06 +0100)
wcfsetup/install/files/lib/system/application/ApplicationHandler.class.php
wcfsetup/install/files/lib/system/request/LinkHandler.class.php

index b0043f54eab7537458c71ec1513ba98693028824..a949d56d030f6496792ca18e89cc7d08913446a1 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\application;
+use wcf\data\application\Application;
 use wcf\data\application\ApplicationAction;
 use wcf\data\application\ApplicationList;
 use wcf\system\cache\builder\ApplicationCacheBuilder;
index 9c51d97d91410f9a7b529078688e73763bc941f1..585ead8002214f6b2314f616df8ddbf4c85e3955 100644 (file)
@@ -3,9 +3,9 @@ namespace wcf\system\request;
 use wcf\data\DatabaseObjectDecorator;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\menu\page\PageMenu;
-use wcf\system\request\RouteHandler;
 use wcf\system\Regex;
 use wcf\system\SingletonFactory;
+use wcf\system\WCF;
 use wcf\util\StringUtil;
 
 /**
@@ -19,6 +19,21 @@ use wcf\util\StringUtil;
  * @category   Community Framework
  */
 class LinkHandler extends SingletonFactory {
+       /**
+        * @var ApplicationHandler
+        */
+       protected $applicationHandler;
+       
+       /**
+        * @var RequestHandler
+        */
+       protected $requestHandler;
+       
+       /**
+        * @var RouteHandler
+        */
+       protected $routeHandler;
+       
        /**
         * regex object to filter title
         * @var \wcf\system\RegEx
@@ -37,6 +52,21 @@ class LinkHandler extends SingletonFactory {
         */
        protected $titleReplace = array();
        
+       /**
+        * LinkHandler constructor.
+        * 
+        * @param       ApplicationHandler      $applicationHandler
+        * @param       RequestHandler          $requestHandler
+        * @param       RouteHandler            $routeHandler
+        */
+       public function __construct(ApplicationHandler $applicationHandler, RequestHandler $requestHandler, RouteHandler $routeHandler) {
+               $this->applicationHandler = $applicationHandler;
+               $this->requestHandler = $requestHandler;
+               $this->routeHandler = $routeHandler;
+               
+               parent::__construct();
+       }
+       
        /**
         * @see \wcf\system\SingletonFactory::init()
         */
@@ -65,7 +95,7 @@ class LinkHandler extends SingletonFactory {
        public function getLink($controller = null, array $parameters = array(), $url = '') {
                $abbreviation = 'wcf';
                $anchor = '';
-               $isACP = $originIsACP = RequestHandler::getInstance()->isACPRequest();
+               $isACP = $originIsACP = $this->requestHandler->isACPRequest();
                $forceWCF = $isRaw = false;
                $appendSession = $encodeTitle = true;
                
@@ -127,7 +157,7 @@ class LinkHandler extends SingletonFactory {
                                $controller = 'Index';
                        }
                        else {
-                               return PageMenu::getInstance()->getLandingPage()->getProcessor()->getLink();
+                               return WCF::getDIContainer()->get(PageMenu::class)->getLandingPage()->getProcessor()->getLink();
                        }
                }
                
@@ -162,7 +192,7 @@ class LinkHandler extends SingletonFactory {
                }
                
                $parameters['controller'] = $controller;
-               $routeURL = RouteHandler::getInstance()->buildRoute($parameters, $isACP);
+               $routeURL = $this->routeHandler->buildRoute($parameters, $isACP);
                if (!$isRaw && !empty($url)) {
                        $routeURL .= (strpos($routeURL, '?') === false) ? '?' : '&';
                }
@@ -184,22 +214,22 @@ class LinkHandler extends SingletonFactory {
                        $url = RouteHandler::getHost() . RouteHandler::getPath(array('acp')) . ($isACP ? 'acp/' : '') . $url;
                }
                else {
-                       if (RequestHandler::getInstance()->inRescueMode()) {
+                       if ($this->requestHandler->inRescueMode()) {
                                $pageURL = RouteHandler::getHost() . str_replace('//', '/', RouteHandler::getPath(array('acp')));
                        }
                        else {
                                // try to resolve abbreviation
                                $application = null;
                                if ($abbreviation != 'wcf') {
-                                       $application = ApplicationHandler::getInstance()->getApplication($abbreviation);
+                                       $application = $this->applicationHandler->getApplication($abbreviation);
                                }
                                
                                // fallback to primary application if abbreviation is 'wcf' or unknown
                                if ($forceWCF) {
-                                       $application = ApplicationHandler::getInstance()->getWCF();
+                                       $application = $this->applicationHandler->getWCF();
                                }
                                else if ($application === null) {
-                                       $application = ApplicationHandler::getInstance()->getPrimaryApplication();
+                                       $application = $this->applicationHandler->getPrimaryApplication();
                                }
                                
                                $pageURL = $application->getPageURL();