PluginProbe
WPIDE – File Manager & Code Editor / 3.5.9
WPIDE – File Manager & Code Editor v3.5.9
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 3.3 All 55 releases
wpide / vendor / nikic / fast-route / src / RouteCollector.php

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

153 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FastRoute;
4
5 class RouteCollector
6 {
7 /** @var RouteParser */
8 protected $routeParser;
9
10 /** @var DataGenerator */
11 protected $dataGenerator;
12
13 /** @var string */
14 protected $currentGroupPrefix;
15
16 /**
17 * Constructs a route collector.
18 *
19 * @param RouteParser $routeParser
20 * @param DataGenerator $dataGenerator
21 */
22 public function __construct(RouteParser $routeParser, DataGenerator $dataGenerator)
23 {
24 $this->routeParser = $routeParser;
25 $this->dataGenerator = $dataGenerator;
26 $this->currentGroupPrefix = '';
27 }
28
29 /**
30 * Adds a route to the collection.
31 *
32 * The syntax used in the $route string depends on the used route parser.
33 *
34 * @param string|string[] $httpMethod
35 * @param string $route
36 * @param mixed $handler
37 */
38 public function addRoute($httpMethod, $route, $handler)
39 {
40 $route = $this->currentGroupPrefix . $route;
41 $routeDatas = $this->routeParser->parse($route);
42 foreach ((array) $httpMethod as $method) {
43 foreach ($routeDatas as $routeData) {
44 $this->dataGenerator->addRoute($method, $routeData, $handler);
45 }
46 }
47 }
48
49 /**
50 * Create a route group with a common prefix.
51 *
52 * All routes created in the passed callback will have the given group prefix prepended.
53 *
54 * @param string $prefix
55 * @param callable $callback
56 */
57 public function addGroup($prefix, callable $callback)
58 {
59 $previousGroupPrefix = $this->currentGroupPrefix;
60 $this->currentGroupPrefix = $previousGroupPrefix . $prefix;
61 $callback($this);
62 $this->currentGroupPrefix = $previousGroupPrefix;
63 }
64
65 /**
66 * Adds a GET route to the collection
67 *
68 * This is simply an alias of $this->addRoute('GET', $route, $handler)
69 *
70 * @param string $route
71 * @param mixed $handler
72 */
73 public function get($route, $handler)
74 {
75 $this->addRoute('GET', $route, $handler);
76 }
77
78 /**
79 * Adds a POST route to the collection
80 *
81 * This is simply an alias of $this->addRoute('POST', $route, $handler)
82 *
83 * @param string $route
84 * @param mixed $handler
85 */
86 public function post($route, $handler)
87 {
88 $this->addRoute('POST', $route, $handler);
89 }
90
91 /**
92 * Adds a PUT route to the collection
93 *
94 * This is simply an alias of $this->addRoute('PUT', $route, $handler)
95 *
96 * @param string $route
97 * @param mixed $handler
98 */
99 public function put($route, $handler)
100 {
101 $this->addRoute('PUT', $route, $handler);
102 }
103
104 /**
105 * Adds a DELETE route to the collection
106 *
107 * This is simply an alias of $this->addRoute('DELETE', $route, $handler)
108 *
109 * @param string $route
110 * @param mixed $handler
111 */
112 public function delete($route, $handler)
113 {
114 $this->addRoute('DELETE', $route, $handler);
115 }
116
117 /**
118 * Adds a PATCH route to the collection
119 *
120 * This is simply an alias of $this->addRoute('PATCH', $route, $handler)
121 *
122 * @param string $route
123 * @param mixed $handler
124 */
125 public function patch($route, $handler)
126 {
127 $this->addRoute('PATCH', $route, $handler);
128 }
129
130 /**
131 * Adds a HEAD route to the collection
132 *
133 * This is simply an alias of $this->addRoute('HEAD', $route, $handler)
134 *
135 * @param string $route
136 * @param mixed $handler
137 */
138 public function head($route, $handler)
139 {
140 $this->addRoute('HEAD', $route, $handler);
141 }
142
143 /**
144 * Returns the collected route data, as provided by the data generator.
145 *
146 * @return array
147 */
148 public function getData()
149 {
150 return $this->dataGenerator->getData();
151 }
152 }
153