PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / nikic / fast-route / src / RouteCollector.php
ameliabooking / vendor / nikic / fast-route / src Last commit date
DataGenerator 7 years ago Dispatcher 7 years ago RouteParser 7 years ago BadRouteException.php 7 years ago DataGenerator.php 7 years ago Dispatcher.php 7 years ago Route.php 7 years ago RouteCollector.php 7 years ago RouteParser.php 7 years ago bootstrap.php 7 years ago functions.php 7 years ago
RouteCollector.php
153 lines
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