1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Meraki\Route; |
5
|
|
|
|
6
|
|
|
use Meraki\Route\Collection; |
7
|
|
|
use Psr\Http\Server\RequestHandlerInterface as RequestHandler; |
8
|
|
|
use Closure; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* An in-memory store for route rules. |
12
|
|
|
* |
13
|
|
|
* @author Nathan Bishop <[email protected]> (https://nathanbishop.name) |
14
|
|
|
* @copyright 2019 Nathan Bishop |
15
|
|
|
* @license The MIT license. |
16
|
|
|
*/ |
17
|
|
|
final class Mapper extends Collection |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string The request-target prefix. |
21
|
|
|
*/ |
22
|
|
|
private $prefix = ''; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Adds a route that responds to the 'HEAD' request method to the collection. |
26
|
|
|
* |
27
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
28
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
29
|
|
|
* @return Route The actual route object being added to the collection. |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function head(string $requestTarget, RequestHandler $handler): Rule |
32
|
|
|
{ |
33
|
|
|
return $this->map('HEAD', $requestTarget, $handler); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Adds a route that responds to the 'GET' request method to the collection. |
38
|
|
|
* |
39
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
40
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
41
|
|
|
* @return Route The actual route object being added to the collection. |
42
|
|
|
*/ |
43
|
|
|
public function get(string $requestTarget, RequestHandler $handler): Rule |
44
|
|
|
{ |
45
|
|
|
return $this->map('GET', $requestTarget, $handler); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Adds a route that responds to the 'POST' request method to the collection. |
50
|
|
|
* |
51
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
52
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
53
|
|
|
* @return Route The actual route object being added to the collection. |
54
|
|
|
*/ |
55
|
|
|
public function post(string $requestTarget, RequestHandler $handler): Rule |
56
|
|
|
{ |
57
|
|
|
return $this->map('POST', $requestTarget, $handler); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Adds a route that responds to the 'PUT' request method to the collection. |
62
|
|
|
* |
63
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
64
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
65
|
|
|
* @return Route The actual route object being added to the collection. |
66
|
|
|
*/ |
67
|
|
|
public function put(string $requestTarget, RequestHandler $handler): Rule |
68
|
|
|
{ |
69
|
|
|
return $this->map('PUT', $requestTarget, $handler); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Adds a route that responds to the 'PATCH' request method to the collection. |
74
|
|
|
* |
75
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
76
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
77
|
|
|
* @return Route The actual route object being added to the collection. |
78
|
|
|
*/ |
79
|
|
|
public function patch(string $requestTarget, RequestHandler $handler): Rule |
80
|
|
|
{ |
81
|
|
|
return $this->map('PATCH', $requestTarget, $handler); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Adds a route that responds to the 'DELETE' request method to the collection. |
86
|
|
|
* |
87
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
88
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
89
|
|
|
* @return Route The actual route object being added to the collection. |
90
|
|
|
*/ |
91
|
|
|
public function delete(string $requestTarget, RequestHandler $handler): Rule |
92
|
|
|
{ |
93
|
|
|
return $this->map('DELETE', $requestTarget, $handler); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Adds a route that responds to the 'OPTIONS' request method to the collection. |
98
|
|
|
* |
99
|
|
|
* @param string $requestTarget The path/pattern the route should respond to. |
100
|
|
|
* @param callable $handler The method/function to call when a route is matched. |
101
|
|
|
* @return Route The actual route object being added to the collection. |
102
|
|
|
*/ |
103
|
|
|
public function options(string $requestTarget, RequestHandler $handler): Rule |
104
|
|
|
{ |
105
|
|
|
return $this->map('OPTIONS', $requestTarget, $handler); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Add routes with a prefix attached to the request-target. |
110
|
|
|
* |
111
|
|
|
* @param string $prefix The request-target to be prefixed to every added route. |
112
|
|
|
* @param Closure $grouper Routes added from within this closure will be prefixed with the supplied request-target. |
113
|
|
|
*/ |
114
|
|
|
public function group(string $prefix, Closure $grouper): void |
115
|
|
|
{ |
116
|
|
|
$previousPrefix = $this->prefix; |
117
|
|
|
$this->prefix = $previousPrefix . $prefix; |
118
|
|
|
|
119
|
|
|
$grouper->call($this); |
120
|
|
|
|
121
|
|
|
$this->prefix = $previousPrefix; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Create a new route rule and add it to the collection. |
126
|
|
|
* |
127
|
|
|
* @param string $method The request method. |
128
|
|
|
* @param string $requestTarget The request target. |
129
|
|
|
* @param RequestHandler $handler The request handler. |
130
|
|
|
* @return Rule The rule that was created to match the request. |
131
|
|
|
*/ |
132
|
|
|
public function map(string $method, string $requestTarget, RequestHandler $handler): Rule |
133
|
|
|
{ |
134
|
|
|
$rule = Rule::create($method, $this->prefix . $requestTarget, $handler); |
135
|
|
|
|
136
|
|
|
$this->add($rule); |
137
|
|
|
|
138
|
|
|
return $rule; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths