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 / RouteParser / Std.php
ameliabooking / vendor / nikic / fast-route / src / RouteParser Last commit date
Std.php 7 years ago
Std.php
88 lines
1 <?php
2
3 namespace FastRoute\RouteParser;
4
5 use FastRoute\BadRouteException;
6 use FastRoute\RouteParser;
7
8 /**
9 * Parses route strings of the following form:
10 *
11 * "/user/{name}[/{id:[0-9]+}]"
12 */
13 class Std implements RouteParser
14 {
15 const VARIABLE_REGEX = <<<'REGEX'
16 \{
17 \s* ([a-zA-Z_][a-zA-Z0-9_-]*) \s*
18 (?:
19 : \s* ([^{}]*(?:\{(?-1)\}[^{}]*)*)
20 )?
21 \}
22 REGEX;
23 const DEFAULT_DISPATCH_REGEX = '[^/]+';
24
25 public function parse($route)
26 {
27 $routeWithoutClosingOptionals = rtrim($route, ']');
28 $numOptionals = strlen($route) - strlen($routeWithoutClosingOptionals);
29
30 // Split on [ while skipping placeholders
31 $segments = preg_split('~' . self::VARIABLE_REGEX . '(*SKIP)(*F) | \[~x', $routeWithoutClosingOptionals);
32 if ($numOptionals !== count($segments) - 1) {
33 // If there are any ] in the middle of the route, throw a more specific error message
34 if (preg_match('~' . self::VARIABLE_REGEX . '(*SKIP)(*F) | \]~x', $routeWithoutClosingOptionals)) {
35 throw new BadRouteException('Optional segments can only occur at the end of a route');
36 }
37 throw new BadRouteException("Number of opening '[' and closing ']' does not match");
38 }
39
40 $currentRoute = '';
41 $routeDatas = [];
42 foreach ($segments as $n => $segment) {
43 if ($segment === '' && $n !== 0) {
44 throw new BadRouteException('Empty optional part');
45 }
46
47 $currentRoute .= $segment;
48 $routeDatas[] = $this->parsePlaceholders($currentRoute);
49 }
50 return $routeDatas;
51 }
52
53 /**
54 * Parses a route string that does not contain optional segments.
55 *
56 * @param string
57 * @return mixed[]
58 */
59 private function parsePlaceholders($route)
60 {
61 if (!preg_match_all(
62 '~' . self::VARIABLE_REGEX . '~x', $route, $matches,
63 PREG_OFFSET_CAPTURE | PREG_SET_ORDER
64 )) {
65 return [$route];
66 }
67
68 $offset = 0;
69 $routeData = [];
70 foreach ($matches as $set) {
71 if ($set[0][1] > $offset) {
72 $routeData[] = substr($route, $offset, $set[0][1] - $offset);
73 }
74 $routeData[] = [
75 $set[1][0],
76 isset($set[2]) ? trim($set[2][0]) : self::DEFAULT_DISPATCH_REGEX
77 ];
78 $offset = $set[0][1] + strlen($set[0][0]);
79 }
80
81 if ($offset !== strlen($route)) {
82 $routeData[] = substr($route, $offset);
83 }
84
85 return $routeData;
86 }
87 }
88