PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
3.5.10 3.5.9 3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 All 56 releases
wpide / vendor / nikic / fast-route / src / Dispatcher / RegexBasedAbstract.php

RegexBasedAbstract.php in WPIDE – File Manager & Code Editor 3.5.9, at vendor/nikic/fast-route/src/Dispatcher/RegexBasedAbstract.php

89 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FastRoute\Dispatcher;
4
5 use FastRoute\Dispatcher;
6
7 abstract class RegexBasedAbstract implements Dispatcher
8 {
9 /** @var mixed[][] */
10 protected $staticRouteMap = [];
11
12 /** @var mixed[] */
13 protected $variableRouteData = [];
14
15 /**
16 * @return mixed[]
17 */
18 abstract protected function dispatchVariableRoute($routeData, $uri);
19
20 public function dispatch($httpMethod, $uri)
21 {
22 if (isset($this->staticRouteMap[$httpMethod][$uri])) {
23 $handler = $this->staticRouteMap[$httpMethod][$uri];
24 return [self::FOUND, $handler, []];
25 }
26
27 $varRouteData = $this->variableRouteData;
28 if (isset($varRouteData[$httpMethod])) {
29 $result = $this->dispatchVariableRoute($varRouteData[$httpMethod], $uri);
30 if ($result[0] === self::FOUND) {
31 return $result;
32 }
33 }
34
35 // For HEAD requests, attempt fallback to GET
36 if ($httpMethod === 'HEAD') {
37 if (isset($this->staticRouteMap['GET'][$uri])) {
38 $handler = $this->staticRouteMap['GET'][$uri];
39 return [self::FOUND, $handler, []];
40 }
41 if (isset($varRouteData['GET'])) {
42 $result = $this->dispatchVariableRoute($varRouteData['GET'], $uri);
43 if ($result[0] === self::FOUND) {
44 return $result;
45 }
46 }
47 }
48
49 // If nothing else matches, try fallback routes
50 if (isset($this->staticRouteMap['*'][$uri])) {
51 $handler = $this->staticRouteMap['*'][$uri];
52 return [self::FOUND, $handler, []];
53 }
54 if (isset($varRouteData['*'])) {
55 $result = $this->dispatchVariableRoute($varRouteData['*'], $uri);
56 if ($result[0] === self::FOUND) {
57 return $result;
58 }
59 }
60
61 // Find allowed methods for this URI by matching against all other HTTP methods as well
62 $allowedMethods = [];
63
64 foreach ($this->staticRouteMap as $method => $uriMap) {
65 if ($method !== $httpMethod && isset($uriMap[$uri])) {
66 $allowedMethods[] = $method;
67 }
68 }
69
70 foreach ($varRouteData as $method => $routeData) {
71 if ($method === $httpMethod) {
72 continue;
73 }
74
75 $result = $this->dispatchVariableRoute($routeData, $uri);
76 if ($result[0] === self::FOUND) {
77 $allowedMethods[] = $method;
78 }
79 }
80
81 // If there are no allowed methods the route simply does not exist
82 if ($allowedMethods) {
83 return [self::METHOD_NOT_ALLOWED, $allowedMethods];
84 }
85
86 return [self::NOT_FOUND];
87 }
88 }
89