|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* It's free open-source software released under the MIT License. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Anatoly Fenric <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Fenric |
|
8
|
|
|
* @license https://github.com/sunrise-php/http-router/blob/master/LICENSE |
|
9
|
|
|
* @link https://github.com/sunrise-php/http-router |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sunrise\Http\Router\Annotation; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Import classes |
|
16
|
|
|
*/ |
|
17
|
|
|
use Attribute; |
|
18
|
|
|
use ReflectionClass; |
|
19
|
|
|
use ReflectionMethod; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @Annotation |
|
23
|
|
|
* |
|
24
|
|
|
* @Target({"CLASS", "METHOD"}) |
|
25
|
|
|
* |
|
26
|
|
|
* @NamedArgumentConstructor |
|
27
|
|
|
* |
|
28
|
|
|
* @Attributes({ |
|
29
|
|
|
* @Attribute("name", type="string", required=true), |
|
30
|
|
|
* @Attribute("host", type="string"), |
|
31
|
|
|
* @Attribute("path", type="string", required=true), |
|
32
|
|
|
* @Attribute("method", type="string"), |
|
33
|
|
|
* @Attribute("methods", type="array<string>"), |
|
34
|
|
|
* @Attribute("middlewares", type="array<string>"), |
|
35
|
|
|
* @Attribute("attributes", type="array"), |
|
36
|
|
|
* @Attribute("summary", type="string"), |
|
37
|
|
|
* @Attribute("description", type="string"), |
|
38
|
|
|
* @Attribute("tags", type="array<string>"), |
|
39
|
|
|
* @Attribute("priority", type="integer"), |
|
40
|
|
|
* }) |
|
41
|
|
|
*/ |
|
42
|
|
|
#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD)] |
|
43
|
|
|
final class Route |
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The descriptor holder |
|
48
|
|
|
* |
|
49
|
|
|
* Don't use the property outside of the package. |
|
50
|
|
|
* |
|
51
|
|
|
* @var ReflectionClass|ReflectionMethod|null |
|
52
|
|
|
* |
|
53
|
|
|
* @internal |
|
54
|
|
|
*/ |
|
55
|
|
|
public $holder = null; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* A route name |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
public $name; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* A route host |
|
66
|
|
|
* |
|
67
|
|
|
* @var string|null |
|
68
|
|
|
*/ |
|
69
|
|
|
public $host; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* A route path |
|
73
|
|
|
* |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
public $path; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* A route methods |
|
80
|
|
|
* |
|
81
|
|
|
* @var string[] |
|
82
|
|
|
*/ |
|
83
|
|
|
public $methods; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* A route middlewares |
|
87
|
|
|
* |
|
88
|
|
|
* @var string[] |
|
89
|
|
|
*/ |
|
90
|
|
|
public $middlewares; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* A route attributes |
|
94
|
|
|
* |
|
95
|
|
|
* @var array |
|
96
|
|
|
*/ |
|
97
|
|
|
public $attributes; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* A route summary |
|
101
|
|
|
* |
|
102
|
|
|
* @var string |
|
103
|
|
|
*/ |
|
104
|
|
|
public $summary; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* A route description |
|
108
|
|
|
* |
|
109
|
|
|
* @var string |
|
110
|
|
|
*/ |
|
111
|
|
|
public $description; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* A route tags |
|
115
|
|
|
* |
|
116
|
|
|
* @var string[] |
|
117
|
|
|
*/ |
|
118
|
|
|
public $tags; |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* A route priority |
|
122
|
|
|
* |
|
123
|
|
|
* @var int |
|
124
|
|
|
*/ |
|
125
|
|
|
public $priority; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Constructor of the class |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $name The route name |
|
131
|
|
|
* @param string|null $host The route host |
|
132
|
|
|
* @param string $path The route path |
|
133
|
|
|
* @param string|null $method The route method |
|
134
|
|
|
* @param string[] $methods The route methods |
|
135
|
|
|
* @param string[] $middlewares The route middlewares |
|
136
|
|
|
* @param array $attributes The route attributes |
|
137
|
|
|
* @param string $summary The route summary |
|
138
|
|
|
* @param string $description The route description |
|
139
|
|
|
* @param string[] $tags The route tags |
|
140
|
|
|
* @param int $priority The route priority (default 0) |
|
141
|
|
|
*/ |
|
142
|
10 |
|
public function __construct( |
|
143
|
|
|
string $name, |
|
144
|
|
|
?string $host = null, |
|
145
|
|
|
string $path, |
|
146
|
|
|
?string $method = null, |
|
147
|
|
|
array $methods = [], |
|
148
|
|
|
array $middlewares = [], |
|
149
|
|
|
array $attributes = [], |
|
150
|
|
|
string $summary = '', |
|
151
|
|
|
string $description = '', |
|
152
|
|
|
array $tags = [], |
|
153
|
|
|
int $priority = 0 |
|
154
|
|
|
) { |
|
155
|
10 |
|
if (isset($method)) { |
|
156
|
9 |
|
$methods[] = $method; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
10 |
|
$this->name = $name; |
|
160
|
10 |
|
$this->host = $host; |
|
161
|
10 |
|
$this->path = $path; |
|
162
|
10 |
|
$this->methods = $methods; |
|
163
|
10 |
|
$this->middlewares = $middlewares; |
|
164
|
10 |
|
$this->attributes = $attributes; |
|
165
|
10 |
|
$this->summary = $summary; |
|
166
|
10 |
|
$this->description = $description; |
|
167
|
10 |
|
$this->tags = $tags; |
|
168
|
10 |
|
$this->priority = $priority; |
|
169
|
10 |
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|