Removed outdated and broken route implementations
authorAlexander Ebert <ebert@woltlab.com>
Thu, 11 Aug 2016 17:03:17 +0000 (19:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 11 Aug 2016 17:03:21 +0000 (19:03 +0200)
wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php [deleted file]
wcfsetup/install/files/lib/system/request/IRoute.class.php [deleted file]
wcfsetup/install/files/lib/system/request/RouteHandler.class.php
wcfsetup/install/files/lib/system/request/StaticRoute.class.php [deleted file]
wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php

diff --git a/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php b/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php
deleted file mode 100644 (file)
index 178d898..0000000
+++ /dev/null
@@ -1,302 +0,0 @@
-<?php
-namespace wcf\system\request;
-
-/**
- * Flexible route implementation to resolve HTTP requests.
- * 
- * Inspired by routing mechanism used by ASP.NET MVC and released under the terms of
- * the Microsoft Public License (MS-PL) http://www.opensource.org/licenses/ms-pl.html
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2016 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\System\Request
- * @deprecated  3.0 Consider using \wcf\system\request\route\DynamicRequestRoute
- */
-class FlexibleRoute implements IRoute {
-       /**
-        * schema for outgoing links
-        * @var mixed[][]
-        */
-       protected $buildSchema = [];
-       
-       /**
-        * route is restricted to ACP
-        * @var boolean
-        */
-       protected $isACP = false;
-       
-       /**
-        * pattern for incoming requests
-        * @var string
-        */
-       protected $pattern = '';
-       
-       /**
-        * list of required components
-        * @var string[]
-        */
-       protected $requireComponents = [];
-       
-       /**
-        * parsed request data
-        * @var mixed[]
-        */
-       protected $routeData = [];
-       
-       /**
-        * Creates a new flexible route instace.
-        * 
-        * @param       boolean         $isACP
-        */
-       public function __construct($isACP) {
-               $this->isACP = $isACP;
-               
-               $this->pattern = '~
-                       /?
-                       (?:
-                               (?P<controller>[A-Za-z0-9\-]+)
-                               (?:
-                                       /
-                                       (?P<id>\d+)
-                                       (?:
-                                               -
-                                               (?P<title>[^/]+)
-                                       )?
-                               )?
-                       )?
-               ~x';
-               $this->setBuildSchema('/{controller}/{id}-{title}/');
-       }
-       
-       /**
-        * Sets the build schema used to build outgoing links.
-        * 
-        * @param       string          $buildSchema
-        */
-       public function setBuildSchema($buildSchema) {
-               $this->buildSchema = [];
-               
-               $buildSchema = ltrim($buildSchema, '/');
-               $components = preg_split('~({(?:[a-z]+)})~', $buildSchema, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
-               
-               foreach ($components as $component) {
-                       $type = 'component';
-                       if (preg_match('~{([a-z]+)}~', $component, $matches)) {
-                               $component = $matches[1];
-                       }
-                       else {
-                               $type = 'separator';
-                       }
-                       
-                       $this->buildSchema[] = [
-                               'type' => $type,
-                               'value' => $component
-                       ];
-               }
-       }
-       
-       /**
-        * Sets the route pattern used to evaluate an incoming request.
-        * 
-        * @param       string          $pattern
-        */
-       public function setPattern($pattern) {
-               $this->pattern = $pattern;
-       }
-       
-       /**
-        * Sets the list of required components.
-        * 
-        * @param       string[]        $requiredComponents
-        */
-       public function setRequiredComponents(array $requiredComponents) {
-               $this->requireComponents = $requiredComponents;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function buildLink(array $components) {
-               $application = isset($components['application']) ? $components['application'] : null;
-               
-               // drop application component to avoid being appended as query string
-               unset($components['application']);
-               
-               // handle default values for controller
-               $useBuildSchema = true;
-               if (count($components) == 1 && isset($components['controller'])) {
-                       $ignoreController = false;
-                       
-                       if (!RequestHandler::getInstance()->isACPRequest()) {
-                               // TODO
-                               //$landingPage = PageMenu::getInstance()->getLandingPage();
-                               $landingPage = null;
-                               
-                               // check if this is the default controller
-                               if (strcasecmp(RouteHandler::getInstance()->getDefaultController($application), $components['controller']) === 0) {
-                                       // check if this matches the primary application
-                                       /*
-                                        * TODO: what exactly is this doing?
-                                        */
-                                       /*if ($this->primaryApplication === $application) {
-                                               if (strcasecmp($landingPage->getController(), $components['controller']) === 0) {
-                                                       // skip controller if it matches the default controller
-                                                       $ignoreController = true;
-                                               }
-                                       }
-                                       else {
-                                               // skip default controller
-                                               $ignoreController = true;
-                                       }
-                                       */
-                               }
-                               else if (strcasecmp($landingPage->getController(), $components['controller']) === 0) {
-                                       // landing page
-                                       $ignoreController = true;
-                               }
-                       }
-                       
-                       // drops controller from route
-                       if ($ignoreController) {
-                               $useBuildSchema = false;
-                               
-                               // unset the controller, since it would otherwise be added with http_build_query()
-                               unset($components['controller']);
-                       }
-               }
-               
-               return $this->buildRoute($components, $application, $useBuildSchema);
-       }
-       
-       /**
-        * Builds the actual link, the parameter $useBuildSchema can be set to false for
-        * empty routes, e.g. for the default page.
-        * 
-        * @param       array           $components
-        * @param       string          $application
-        * @param       boolean         $useBuildSchema
-        * @return      string
-        */
-       protected function buildRoute(array $components, $application, $useBuildSchema) {
-               $link = '';
-               
-               if ($useBuildSchema) {
-                       $lastSeparator = null;
-                       $skipToLastSeparator = false;
-                       foreach ($this->buildSchema as $component) {
-                               $value = $component['value'];
-                               
-                               if ($component['type'] === 'separator') {
-                                       $lastSeparator = $value;
-                               }
-                               else if ($skipToLastSeparator === false) {
-                                       // routes are build from left-to-right
-                                       if (empty($components[$value])) {
-                                               $skipToLastSeparator = true;
-                                               
-                                               // drop empty components to avoid them being appended as query string argument
-                                               unset($components[$value]);
-                                               
-                                               continue;
-                                       }
-                                       
-                                       if ($lastSeparator !== null) {
-                                               $link .= $lastSeparator;
-                                               $lastSeparator = null;
-                                       }
-                                       
-                                       // handle controller names
-                                       if ($value === 'controller') {
-                                               $components[$value] = $this->getControllerName($application, $components[$value]);
-                                       }
-                                       
-                                       $link .= $components[$value];
-                                       unset($components[$value]);
-                               }
-                       }
-                       
-                       if (!empty($link) && $lastSeparator !== null) {
-                               $link .= $lastSeparator;
-                       }
-               }
-               
-               if ($this->isACP || !URL_OMIT_INDEX_PHP) {
-                       if (!empty($link)) {
-                               $link = 'index.php?' . $link;
-                       }
-               }
-               
-               if (!empty($components)) {
-                       if (strpos($link, '?') === false) $link .= '?';
-                       else $link .= '&';
-                       
-                       $link .= http_build_query($components, '', '&');
-               }
-               
-               return $link;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function canHandle(array $components) {
-               if (!empty($this->requireComponents)) {
-                       foreach ($this->requireComponents as $component => $pattern) {
-                               if (empty($components[$component])) {
-                                       return false;
-                               }
-                               
-                               if ($pattern && !preg_match($pattern, $components[$component])) {
-                                       return false;
-                               }
-                       }
-               }
-               
-               return true;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function getRouteData() {
-               return $this->routeData;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function isACP() {
-               return $this->isACP;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function matches($requestURL) {
-               if (preg_match($this->pattern, $requestURL, $matches)) {
-                       foreach ($matches as $key => $value) {
-                               if (!is_numeric($key)) {
-                                       $this->routeData[$key] = $value;
-                               }
-                       }
-                       
-                       $this->routeData['isDefaultController'] = (!isset($this->routeData['controller']));
-                       
-                       return true;
-               }
-               
-               return false;
-       }
-       
-       /**
-        * Returns the transformed controller name.
-        * 
-        * @param       string          $application
-        * @param       string          $controller
-        * @return      string
-        */
-       protected function getControllerName($application, $controller) {
-               return RequestHandler::getInstance()->getControllerMap()->lookup($controller);
-       }
-}
diff --git a/wcfsetup/install/files/lib/system/request/IRoute.class.php b/wcfsetup/install/files/lib/system/request/IRoute.class.php
deleted file mode 100644 (file)
index 5545931..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-namespace wcf\system\request;
-
-/**
- * Default interface for route implementations.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2016 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\System\Request
- * @deprecated  3.0 will be replaced with \wcf\system\request\route\IRequestRoute
- */
-interface IRoute {
-       /**
-        * Builds a link upon route components.
-        * 
-        * @param       array           $components
-        * @return      string
-        */
-       public function buildLink(array $components);
-       
-       /**
-        * Returns true if current route can handle the build request.
-        * 
-        * @param       array           $components
-        * @return      boolean
-        */
-       public function canHandle(array $components);
-       
-       /**
-        * Returns parsed route data.
-        * 
-        * @return      array
-        */
-       public function getRouteData();
-       
-       /**
-        * Returns true if route applies for ACP.
-        * 
-        * @return      boolean
-        */
-       public function isACP();
-       
-       /**
-        * Returns true if given request url matches this route.
-        * 
-        * @param       string          $requestURL
-        * @return      boolean
-        */
-       public function matches($requestURL);
-}
index 99d788d3e326daf8a2beaba70b981a0709cedc22..6f60322867fdcfe463c1dbf5a04efa149dccef65 100644 (file)
@@ -4,6 +4,7 @@ use wcf\system\application\ApplicationHandler;
 use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\request\route\DynamicRequestRoute;
+use wcf\system\request\route\IRequestRoute;
 use wcf\system\request\route\LookupRequestRoute;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
@@ -65,7 +66,7 @@ class RouteHandler extends SingletonFactory {
        
        /**
         * list of available routes
-        * @var IRoute[]
+        * @var IRequestRoute[]
         */
        protected $routes = [];
        
@@ -96,16 +97,16 @@ class RouteHandler extends SingletonFactory {
        /**
         * Adds a new route to the beginning of all routes.
         * 
-        * @param       IRoute  $route
+        * @param       IRequestRoute   $route
         */
-       public function addRoute(IRoute $route) {
+       public function addRoute(IRequestRoute $route) {
                array_unshift($this->routes, $route);
        }
        
        /**
         * Returns all registered routes. 
         * 
-        * @return      IRoute[]
+        * @return      IRequestRoute[]
         **/
        public function getRoutes() {
                return $this->routes; 
diff --git a/wcfsetup/install/files/lib/system/request/StaticRoute.class.php b/wcfsetup/install/files/lib/system/request/StaticRoute.class.php
deleted file mode 100644 (file)
index 4b31e15..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-namespace wcf\system\request;
-
-/**
- * Static route implementation to resolve HTTP requests, handling a single controller.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2016 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\System\Request
- * @deprecated  3.0 Consider using \wcf\system\request\route\StaticRequestRoute
- */
-class StaticRoute extends FlexibleRoute {
-       /**
-        * static application identifier
-        * @var string
-        */
-       protected $staticApplication = '';
-       
-       /**
-        * static controller name, not the FQN
-        * @var string
-        */
-       protected $staticController = '';
-       
-       /**
-        * Creates a new static route instance.
-        */
-       public function __construct() {
-               // static routes are disallowed for ACP
-               parent::__construct(false);
-       }
-       
-       /**
-        * Sets the static controller for this route.
-        * 
-        * @param       string          $application
-        * @param       string          $controller
-        */
-       public function setStaticController($application, $controller) {
-               $this->staticApplication = $application;
-               $this->staticController = $controller;
-               
-               $this->requireComponents['controller'] = '~^' . $this->staticController . '$~';
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function buildLink(array $components) {
-               // static routes don't have these components
-               unset($components['application']);
-               unset($components['controller']);
-               
-               return $this->buildRoute($components, '', true);
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function canHandle(array $components) {
-               if (isset($components['application']) && $components['application'] == $this->staticApplication) {
-                       if (isset($components['controller']) && $components['controller'] == $this->staticController) {
-                               return parent::canHandle($components);
-                       }
-               }
-               
-               return false;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function matches($requestURL) {
-               if (parent::matches($requestURL)) {
-                       $this->routeData['application'] = $this->staticApplication;
-                       $this->routeData['controller'] = RequestHandler::getTokenizedController($this->staticController);
-                       $this->routeData['isDefaultController'] = false;
-                       
-                       return true;
-               }
-               
-               return false;
-       }
-}
index c0ebc03a504a840dba82947221ef0c2d8edac0e9..2093019ca5bfeec22674f10d346ef6ee679dbee6 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\request\route;
-use wcf\system\request\IRoute;
 
 /**
  * Default interface for route implementations.
@@ -11,10 +10,48 @@ use wcf\system\request\IRoute;
  * @package    WoltLabSuite\Core\System\Request
  * @since      3.0
  */
-interface IRequestRoute extends IRoute {
+interface IRequestRoute {
+       /**
+        * Builds a link upon route components.
+        *
+        * @param       array           $components
+        * @return      string
+        */
+       public function buildLink(array $components);
+       
+       /**
+        * Returns true if current route can handle the build request.
+        *
+        * @param       array           $components
+        * @return      boolean
+        */
+       public function canHandle(array $components);
+       
+       /**
+        * Returns parsed route data.
+        *
+        * @return      array
+        */
+       public function getRouteData();
+       
+       /**
+        * Returns true if route applies for ACP.
+        *
+        * @return      boolean
+        */
+       public function isACP();
+       
+       /**
+        * Returns true if given request url matches this route.
+        *
+        * @param       string          $requestURL
+        * @return      boolean
+        */
+       public function matches($requestURL);
+       
        /**
         * Configures this route to handle either ACP or frontend requests.
-        * 
+        *
         * @param       boolean         $isACP          true if route handles ACP requests
         */
        public function setIsACP($isACP);