1
|
|
|
<?php |
2
|
|
|
namespace Wandu\Router; |
3
|
|
|
|
4
|
|
|
use Wandu\Router\Contracts\RouteFluent; |
5
|
|
|
use Wandu\Router\Contracts\RouteInformation; |
6
|
|
|
|
7
|
|
|
class Route implements RouteFluent, RouteInformation |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
protected $className; |
11
|
|
|
|
12
|
|
|
/** @var string */ |
13
|
|
|
protected $methodName; |
14
|
|
|
|
15
|
|
|
/** @var array */ |
16
|
|
|
protected $middlewares; |
17
|
|
|
|
18
|
|
|
/** @var array */ |
19
|
|
|
protected $domains; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $className |
23
|
|
|
* @param string $methodName |
24
|
|
|
* @param string|array $middlewares |
25
|
|
|
* @param string|array $domains |
26
|
|
|
*/ |
27
|
23 |
|
public function __construct($className, $methodName, $middlewares = [], $domains = []) |
28
|
|
|
{ |
29
|
23 |
|
$this->className = $className; |
30
|
23 |
|
$this->methodName = $methodName; |
31
|
23 |
|
$this->middlewares = is_array($middlewares) ? $middlewares : [$middlewares]; |
32
|
23 |
|
$this->domains = is_array($domains) ? $domains : [$domains]; |
33
|
23 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
1 |
|
public function middleware($middlewares, $overwrite = false): RouteFluent |
39
|
|
|
{ |
40
|
1 |
|
if (is_string($middlewares)) { |
41
|
1 |
|
$middlewares = [$middlewares]; |
42
|
|
|
} |
43
|
1 |
|
$this->middlewares = $overwrite |
44
|
1 |
|
? $middlewares |
45
|
1 |
|
: array_merge($this->middlewares, $middlewares); |
46
|
1 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
1 |
|
public function domains($domains = []): RouteFluent |
53
|
|
|
{ |
54
|
1 |
|
if (is_string($domains)) { |
55
|
|
|
$domains = [$domains]; |
56
|
|
|
} |
57
|
1 |
|
$this->domains = $domains; |
58
|
1 |
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
19 |
|
public function getDomains(): array |
65
|
|
|
{ |
66
|
19 |
|
return $this->domains; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
21 |
|
public function getClassName(): string |
73
|
|
|
{ |
74
|
21 |
|
return $this->className; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
21 |
|
public function getMethodName(): string |
81
|
|
|
{ |
82
|
21 |
|
return $this->methodName; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
22 |
|
public function getMiddlewares(): array |
89
|
|
|
{ |
90
|
22 |
|
return $this->middlewares; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|