3 namespace wcf\system\request\route
;
5 use wcf\system\application\ApplicationHandler
;
6 use wcf\system\request\ControllerMap
;
10 * Attempts to resolve arbitrary request URLs against the list of known custom
11 * controller URLs, optionally recognizing id and title parameter.
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Request
19 class LookupRequestRoute
implements IRequestRoute
22 * list of parsed route information
25 protected $routeData = [];
30 public function matches($requestURL)
32 $requestURL = FileUtil
::removeLeadingSlash($requestURL);
34 if ($requestURL === '') {
35 // ignore empty urls and let them be handled by regular routes
52 if (\
preg_match($regex, $requestURL, $matches)) {
53 $application = ApplicationHandler
::getInstance()->getActiveApplication()->getAbbreviation();
54 if (!empty($matches['id'])) {
55 // check for static controller URLs
56 $this->routeData
= ControllerMap
::getInstance()->resolveCustomController(
58 FileUtil
::removeTrailingSlash($matches['controller'])
61 // lookup WCF controllers unless initial request targeted WCF itself
62 if (empty($this->routeData
) && $application !== 'wcf') {
63 $this->routeData
= ControllerMap
::getInstance()->resolveCustomController(
65 FileUtil
::removeTrailingSlash($matches['controller'])
69 if (!empty($this->routeData
)) {
70 if (!empty($matches['id'])) {
71 $this->routeData
['id'] = $matches['id'];
73 if (!empty($matches['title'])) {
74 $this->routeData
['title'] = $matches['title'];
80 if (empty($this->routeData
)) {
81 // try to match the entire url
82 $this->routeData
= ControllerMap
::getInstance()->resolveCustomController(
84 FileUtil
::removeTrailingSlash($requestURL)
87 // lookup WCF controllers unless initial request targeted WCF itself
88 if (empty($this->routeData
) && $application !== 'wcf') {
89 $this->routeData
= ControllerMap
::getInstance()->resolveCustomController(
91 FileUtil
::removeTrailingSlash($requestURL)
97 if (!empty($this->routeData
)) {
98 $this->routeData
['isDefaultController'] = false;
109 public function getRouteData()
111 return $this->routeData
;
117 public function setIsACP($isACP)
119 throw new \
BadMethodCallException('lookups are not supported for ACP requests');
124 * @throws \BadMethodCallException
126 public function buildLink(array $components)
128 throw new \
BadMethodCallException(
129 'LookupRequestRoute cannot build links, please verify capabilities by calling canHandle() first.'
136 public function canHandle(array $components)
138 // this route cannot build routes, it is a one-way resolver
145 public function isACP()
147 // lookups are not supported for ACP requests