1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace League\Route; |
4
|
|
|
|
5
|
|
|
trait RouteCollectionTrait |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Add a route to the map. |
9
|
|
|
* |
10
|
|
|
* @param string $method |
11
|
|
|
* @param string $path |
12
|
|
|
* @param callable|string $handler |
13
|
|
|
* |
14
|
|
|
* @return \League\Route\Route |
15
|
|
|
*/ |
16
|
|
|
abstract public function map(string $method, string $path, $handler); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Add a route that responds to GET HTTP method. |
20
|
|
|
* |
21
|
|
|
* @param string $path |
22
|
|
|
* @param callable|string $handler |
23
|
|
|
* |
24
|
|
|
* @return \League\Route\Route |
25
|
|
|
*/ |
26
|
6 |
|
public function get($path, $handler) |
27
|
|
|
{ |
28
|
6 |
|
return $this->map('GET', $path, $handler); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Add a route that responds to POST HTTP method. |
33
|
|
|
* |
34
|
|
|
* @param string $path |
35
|
|
|
* @param callable|string $handler |
36
|
|
|
* |
37
|
|
|
* @return \League\Route\Route |
38
|
|
|
*/ |
39
|
3 |
|
public function post($path, $handler) |
40
|
|
|
{ |
41
|
3 |
|
return $this->map('POST', $path, $handler); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Add a route that responds to PUT HTTP method. |
46
|
|
|
* |
47
|
|
|
* @param string $path |
48
|
|
|
* @param callable|string $handler |
49
|
|
|
* |
50
|
|
|
* @return \League\Route\Route |
51
|
|
|
*/ |
52
|
3 |
|
public function put($path, $handler) |
53
|
|
|
{ |
54
|
3 |
|
return $this->map('PUT', $path, $handler); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Add a route that responds to PATCH HTTP method. |
59
|
|
|
* |
60
|
|
|
* @param string $path |
61
|
|
|
* @param callable|string $handler |
62
|
|
|
* |
63
|
|
|
* @return \League\Route\Route |
64
|
|
|
*/ |
65
|
3 |
|
public function patch($path, $handler) |
66
|
|
|
{ |
67
|
3 |
|
return $this->map('PATCH', $path, $handler); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Add a route that responds to DELETE HTTP method. |
72
|
|
|
* |
73
|
|
|
* @param string $path |
74
|
|
|
* @param callable|string $handler |
75
|
|
|
* |
76
|
|
|
* @return \League\Route\Route |
77
|
|
|
*/ |
78
|
3 |
|
public function delete($path, $handler) |
79
|
|
|
{ |
80
|
3 |
|
return $this->map('DELETE', $path, $handler); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Add a route that responds to HEAD HTTP method. |
85
|
|
|
* |
86
|
|
|
* @param string $path |
87
|
|
|
* @param callable|string $handler |
88
|
|
|
* |
89
|
|
|
* @return \League\Route\Route |
90
|
|
|
*/ |
91
|
3 |
|
public function head($path, $handler) |
92
|
|
|
{ |
93
|
3 |
|
return $this->map('HEAD', $path, $handler); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Add a route that responds to OPTIONS HTTP method. |
98
|
|
|
* |
99
|
|
|
* @param string $path |
100
|
|
|
* @param callable|string $handler |
101
|
|
|
* |
102
|
|
|
* @return \League\Route\Route |
103
|
|
|
*/ |
104
|
3 |
|
public function options($path, $handler) |
105
|
|
|
{ |
106
|
3 |
|
return $this->map('OPTIONS', $path, $handler); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|