From 7faef021fdcd50b2cbe3bc57f19e420ecc4f53b5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 11 Aug 2016 19:03:17 +0200 Subject: [PATCH] Removed outdated and broken route implementations --- .../system/request/FlexibleRoute.class.php | 302 ------------------ .../files/lib/system/request/IRoute.class.php | 51 --- .../lib/system/request/RouteHandler.class.php | 9 +- .../lib/system/request/StaticRoute.class.php | 85 ----- .../request/route/IRequestRoute.class.php | 43 ++- 5 files changed, 45 insertions(+), 445 deletions(-) delete mode 100644 wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php delete mode 100644 wcfsetup/install/files/lib/system/request/IRoute.class.php delete mode 100644 wcfsetup/install/files/lib/system/request/StaticRoute.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 index 178d8986e9..0000000000 --- a/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php +++ /dev/null @@ -1,302 +0,0 @@ - - * @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[A-Za-z0-9\-]+) - (?: - / - (?P\d+) - (?: - - - (?P[^/]+) - )? - )? - )? - ~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 index 55459315f8..0000000000 --- a/wcfsetup/install/files/lib/system/request/IRoute.class.php +++ /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); -} diff --git a/wcfsetup/install/files/lib/system/request/RouteHandler.class.php b/wcfsetup/install/files/lib/system/request/RouteHandler.class.php index 99d788d3e3..6f60322867 100644 --- a/wcfsetup/install/files/lib/system/request/RouteHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RouteHandler.class.php @@ -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 index 4b31e15eff..0000000000 --- a/wcfsetup/install/files/lib/system/request/StaticRoute.class.php +++ /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; - } -} diff --git a/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php index c0ebc03a50..2093019ca5 100644 --- a/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php @@ -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); -- 2.20.1