|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @author Anton Titov (Wolfy-J) |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Spiral\Router\Annotation; |
|
13
|
|
|
|
|
14
|
|
|
use Attribute; |
|
15
|
|
|
use Doctrine\Common\Annotations\Annotation; |
|
16
|
|
|
use Spiral\Attributes\NamedArgumentConstructor; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @Annotation() |
|
20
|
|
|
* @Annotation\Target({"METHOD"}) |
|
21
|
|
|
* @NamedArgumentConstructor() |
|
22
|
|
|
*/ |
|
23
|
|
|
#[Attribute(Attribute::TARGET_METHOD)] |
|
24
|
|
|
#[NamedArgumentConstructor()] |
|
25
|
|
|
final class Route |
|
26
|
|
|
{ |
|
27
|
|
|
public const DEFAULT_GROUP = 'default'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @Annotation\Attribute(name="route", type="string", required=true) |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $route; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @Attribute(name="name", type="string") |
|
37
|
|
|
* @var null|string |
|
38
|
|
|
*/ |
|
39
|
|
|
public $name = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @Annotation\Attribute(name="verbs", type="mixed", required=true) |
|
43
|
|
|
* @var mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
public $methods; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Default match options. |
|
49
|
|
|
* |
|
50
|
|
|
* @Annotation\Attribute(name="defaults", type="array") |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
public $defaults; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Route group (set of middlewere), groups can be configured using MiddlewareRegistry. |
|
57
|
|
|
* |
|
58
|
|
|
* @Annotation\Attribute(name="group", type="string") |
|
59
|
|
|
* @var null|string |
|
60
|
|
|
*/ |
|
61
|
|
|
public $group; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Route specific middleware set, if any. |
|
65
|
|
|
* |
|
66
|
|
|
* @Annotation\Attribute(name="middleware", type="array") |
|
67
|
|
|
* @var array |
|
68
|
|
|
*/ |
|
69
|
|
|
public $middleware; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @Annotation\Attribute(name="priority", type="int") |
|
73
|
|
|
* @var int |
|
74
|
|
|
*/ |
|
75
|
|
|
public $priority; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param array|string $methods |
|
79
|
|
|
*/ |
|
80
|
|
|
public function __construct( |
|
81
|
|
|
string $route, |
|
82
|
|
|
string $name = null, |
|
83
|
|
|
$methods = \Spiral\Router\Route::VERBS, |
|
84
|
|
|
array $defaults = [], |
|
85
|
|
|
string $group = self::DEFAULT_GROUP, |
|
86
|
|
|
array $middleware = [], |
|
87
|
|
|
int $priority = 0 |
|
88
|
|
|
) { |
|
89
|
|
|
$this->route = $route; |
|
90
|
|
|
$this->name = $name; |
|
91
|
|
|
$this->methods = $methods; |
|
92
|
|
|
$this->defaults = $defaults; |
|
93
|
|
|
$this->group = $group; |
|
94
|
|
|
$this->middleware = $middleware; |
|
95
|
|
|
$this->priority = $priority; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|