Server IP : 15.235.198.142 / Your IP : 216.73.216.25 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ballsack 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/share/php/FastRoute/Dispatcher/ |
Upload File : |
<?php namespace FastRoute\Dispatcher; use FastRoute\Dispatcher; abstract class RegexBasedAbstract implements Dispatcher { /** @var mixed[][] */ protected $staticRouteMap = []; /** @var mixed[] */ protected $variableRouteData = []; /** * @return mixed[] */ abstract protected function dispatchVariableRoute($routeData, $uri); public function dispatch($httpMethod, $uri) { if (isset($this->staticRouteMap[$httpMethod][$uri])) { $handler = $this->staticRouteMap[$httpMethod][$uri]; return [self::FOUND, $handler, []]; } $varRouteData = $this->variableRouteData; if (isset($varRouteData[$httpMethod])) { $result = $this->dispatchVariableRoute($varRouteData[$httpMethod], $uri); if ($result[0] === self::FOUND) { return $result; } } // For HEAD requests, attempt fallback to GET if ($httpMethod === 'HEAD') { if (isset($this->staticRouteMap['GET'][$uri])) { $handler = $this->staticRouteMap['GET'][$uri]; return [self::FOUND, $handler, []]; } if (isset($varRouteData['GET'])) { $result = $this->dispatchVariableRoute($varRouteData['GET'], $uri); if ($result[0] === self::FOUND) { return $result; } } } // If nothing else matches, try fallback routes if (isset($this->staticRouteMap['*'][$uri])) { $handler = $this->staticRouteMap['*'][$uri]; return [self::FOUND, $handler, []]; } if (isset($varRouteData['*'])) { $result = $this->dispatchVariableRoute($varRouteData['*'], $uri); if ($result[0] === self::FOUND) { return $result; } } // Find allowed methods for this URI by matching against all other HTTP methods as well $allowedMethods = []; foreach ($this->staticRouteMap as $method => $uriMap) { if ($method !== $httpMethod && isset($uriMap[$uri])) { $allowedMethods[] = $method; } } foreach ($varRouteData as $method => $routeData) { if ($method === $httpMethod) { continue; } $result = $this->dispatchVariableRoute($routeData, $uri); if ($result[0] === self::FOUND) { $allowedMethods[] = $method; } } // If there are no allowed methods the route simply does not exist if ($allowedMethods) { return [self::METHOD_NOT_ALLOWED, $allowedMethods]; } return [self::NOT_FOUND]; } }