1 | <?php |
||
15 | class Route implements Arrayable, Jsonable, JsonSerializable |
||
16 | { |
||
17 | /* ----------------------------------------------------------------- |
||
18 | | Properties |
||
19 | | ----------------------------------------------------------------- |
||
20 | */ |
||
21 | |||
22 | /** @var array */ |
||
23 | public $methods = []; |
||
24 | |||
25 | /** @var string */ |
||
26 | public $uri; |
||
27 | |||
28 | /** @var array */ |
||
29 | public $params = []; |
||
30 | |||
31 | /** @var string */ |
||
32 | public $action; |
||
33 | |||
34 | /** @var string */ |
||
35 | public $name; |
||
36 | |||
37 | /** @var array */ |
||
38 | public $middleware; |
||
39 | |||
40 | /** @var string|null */ |
||
41 | public $domain; |
||
42 | |||
43 | /* ----------------------------------------------------------------- |
||
44 | | Constructor |
||
45 | | ----------------------------------------------------------------- |
||
46 | */ |
||
47 | |||
48 | /** |
||
49 | * Route constructor. |
||
50 | * |
||
51 | * @param array $methods |
||
52 | * @param string $uri |
||
53 | * @param string|null $name |
||
54 | * @param string|null $action |
||
55 | * @param array $middleware |
||
56 | * @param string|null $domain |
||
57 | */ |
||
58 | 28 | public function __construct(array $methods, $uri, $action, $name, array $middleware, $domain = null) |
|
67 | |||
68 | /* ----------------------------------------------------------------- |
||
69 | | Getters & Setters |
||
70 | | ----------------------------------------------------------------- |
||
71 | */ |
||
72 | |||
73 | /** |
||
74 | * Set the route URI. |
||
75 | * |
||
76 | * @param string $uri |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | 28 | private function setUri(string $uri) |
|
89 | |||
90 | /** |
||
91 | * Get the action namespace. |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | 8 | public function getActionNamespace(): string |
|
99 | |||
100 | /** |
||
101 | * Get the action method. |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 8 | public function getActionMethod(): string |
|
109 | |||
110 | /* ----------------------------------------------------------------- |
||
111 | | Check Methods |
||
112 | | ----------------------------------------------------------------- |
||
113 | */ |
||
114 | |||
115 | /** |
||
116 | * Check if the route has name. |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | 8 | public function hasName(): bool |
|
124 | |||
125 | /** |
||
126 | * Check if the route has domain. |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | 4 | public function hasDomain(): bool |
|
134 | |||
135 | /** |
||
136 | * Check if the route has middleware. |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 4 | public function hasMiddleware(): bool |
|
144 | |||
145 | /** |
||
146 | * Check if the action is a closure function. |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | 12 | public function isClosure(): bool |
|
154 | |||
155 | /* ----------------------------------------------------------------- |
||
156 | | Other Methods |
||
157 | | ----------------------------------------------------------------- |
||
158 | */ |
||
159 | |||
160 | /** |
||
161 | * Get the instance as an array. |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 8 | public function toArray(): array |
|
177 | |||
178 | /** |
||
179 | * Convert the object into something JSON serializable. |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | 4 | public function jsonSerialize(): array |
|
187 | |||
188 | /** |
||
189 | * Convert the object to its JSON representation. |
||
190 | * |
||
191 | * @param int $options |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | 4 | public function toJson($options = 0): string |
|
199 | } |
||
200 |