1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bavix\Router; |
4
|
|
|
|
5
|
|
|
class Route implements Routable |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var Match |
10
|
|
|
*/ |
11
|
|
|
protected $match; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @param Match $match |
15
|
|
|
*/ |
16
|
2 |
|
public function __construct(Match $match) |
17
|
|
|
{ |
18
|
2 |
|
$this->match = $match; |
19
|
2 |
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function getProtocol(): string |
25
|
|
|
{ |
26
|
|
|
return $this->match->getProtocol(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function getHost(): string |
33
|
|
|
{ |
34
|
|
|
return $this->match->getHost(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function getName(): string |
41
|
|
|
{ |
42
|
|
|
return $this->match->getRule()->getName(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function getPath(): string |
49
|
|
|
{ |
50
|
|
|
return $this->match->getPath(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getPathPattern(): string |
57
|
|
|
{ |
58
|
|
|
return $this->match->getRule()->getPath()->getPattern(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function getPattern(): string |
65
|
|
|
{ |
66
|
|
|
return $this->match->getPattern(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
2 |
|
public function getAttributes(): array |
73
|
|
|
{ |
74
|
2 |
|
return $this->match->getAttributes(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function getDefaults(): array |
81
|
|
|
{ |
82
|
|
|
return $this->match->getRule()->getDefaults(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
public function getMethods(): array |
89
|
|
|
{ |
90
|
|
|
return $this->match->getRule()->getMethods(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritdoc |
95
|
|
|
*/ |
96
|
|
|
public function serialize(): string |
97
|
|
|
{ |
98
|
|
|
return \serialize($this->match); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @inheritdoc |
103
|
|
|
*/ |
104
|
|
|
public function unserialize($serialized): void |
105
|
|
|
{ |
106
|
|
|
$this->match = \unserialize($serialized, null); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @inheritdoc |
111
|
|
|
*/ |
112
|
|
|
public function jsonSerialize(): array |
113
|
|
|
{ |
114
|
|
|
return [ |
115
|
|
|
'protocol' => $this->getProtocol(), |
116
|
|
|
'host' => $this->getHost(), |
117
|
|
|
'name' => $this->getName(), |
118
|
|
|
'path' => $this->getPath(), |
119
|
|
|
'pathPattern' => $this->getPathPattern(), |
120
|
|
|
'pattern' => $this->getPattern(), |
121
|
|
|
'attributes' => $this->getAttributes(), |
122
|
|
|
'defaults' => $this->getDefaults(), |
123
|
|
|
'methods' => $this->getMethods(), |
124
|
|
|
]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|