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>
18 final class LookupRequestRoute
implements IRequestRoute
21 * list of parsed route information
24 protected array $routeData = [];
29 public function matches($requestURL): bool
31 $requestURL = FileUtil
::removeLeadingSlash($requestURL);
33 if ($requestURL === '') {
34 // ignore empty urls and let them be handled by regular routes
51 if (\
preg_match($regex, $requestURL, $matches)) {
52 $application = ApplicationHandler
::getInstance()->getActiveApplication()->getAbbreviation();
53 if (!empty($matches['id'])) {
54 // check for static controller URLs
55 $this->routeData
= ControllerMap
::getInstance()->resolveCustomController(
57 FileUtil
::removeTrailingSlash($matches['controller'])
60 if ($this->routeData
!== []) {
61 if (!empty($matches['id'])) {
62 $this->routeData
['id'] = $matches['id'];
64 if (!empty($matches['title'])) {
65 $this->routeData
['title'] = $matches['title'];
71 if ($this->routeData
=== []) {
72 // try to match the entire url
73 $this->routeData
= ControllerMap
::getInstance()->resolveCustomController(
75 FileUtil
::removeTrailingSlash($requestURL)
80 if ($this->routeData
!== []) {
81 $this->routeData
['isDefaultController'] = false;
92 public function getRouteData(): array
94 return $this->routeData
;
99 * @throws \BadMethodCallException
101 public function buildLink(array $components): string
103 throw new \
BadMethodCallException(
104 'LookupRequestRoute cannot build links, please verify capabilities by calling canHandle() first.'
111 public function canHandle(array $components): bool
113 // this route cannot build routes, it is a one-way resolver
120 public function isACP(): bool
122 // lookups are not supported for ACP requests