Improved static routes
authorAlexander Ebert <ebert@woltlab.com>
Thu, 8 Sep 2016 18:37:19 +0000 (20:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 8 Sep 2016 18:37:19 +0000 (20:37 +0200)
wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php

index 532ed04ef406f2ea6f38fbb725400ecc783bd829..62ee842cb306cfaa6fd4cca00981ae0a13d9b533 100644 (file)
@@ -12,6 +12,12 @@ use wcf\system\request\ControllerMap;
  * @since      3.0
  */
 class StaticRequestRoute extends DynamicRequestRoute {
+       /**
+        * controller must be present and match the static controller
+        * @var boolean
+        */
+       protected $matchController = false;
+       
        /**
         * static application identifier
         * @var string
@@ -32,6 +38,16 @@ class StaticRequestRoute extends DynamicRequestRoute {
                parent::setIsACP(false);
        }
        
+       /**
+        * Controller must be part of the url and match the static controller, useful
+        * for controllers requiring a custom set of additional parameters.
+        * 
+        * @param       boolean         $matchController
+        */
+       public function setMatchController($matchController) {
+               $this->matchController = $matchController;
+       }
+       
        /**
         * Sets the static controller for this route.
         *
@@ -49,6 +65,10 @@ class StaticRequestRoute extends DynamicRequestRoute {
         * @inheritDoc
         */
        public function buildLink(array $components) {
+               if ($this->matchController) {
+                       return parent::buildLink($components);
+               }
+               
                // static routes don't have these components
                unset($components['application']);
                unset($components['controller']);
@@ -74,8 +94,13 @@ class StaticRequestRoute extends DynamicRequestRoute {
         */
        public function matches($requestURL) {
                if (parent::matches($requestURL)) {
+                       $controller = ControllerMap::getInstance()->lookup($this->staticApplication, $this->staticController);
+                       if ($this->matchController && $this->routeData['controller'] !== $controller) {
+                               return false;
+                       }
+                       
                        $this->routeData['application'] = $this->staticApplication;
-                       $this->routeData['controller'] = ControllerMap::getInstance()->lookup($this->staticApplication, $this->staticController);
+                       $this->routeData['controller'] = $controller;
                        $this->routeData['isDefaultController'] = false;
                        
                        return true;