From 45762819304dc6ebd8677dddb7233ee0c942f0be Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 8 Sep 2016 20:37:19 +0200 Subject: [PATCH] Improved static routes --- .../route/StaticRequestRoute.class.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php index 532ed04ef4..62ee842cb3 100644 --- a/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php @@ -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; -- 2.20.1