1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Rpc\Routing; |
4
|
|
|
|
5
|
|
|
class Route |
6
|
|
|
{ |
7
|
|
|
/** @var string */ |
8
|
|
|
private $method; |
9
|
|
|
/** @var string */ |
10
|
|
|
private $controller; |
11
|
|
|
/** @var array */ |
12
|
|
|
private $context; |
13
|
|
|
/** @var bool */ |
14
|
|
|
private $defaultContext; |
15
|
|
|
/** @var bool */ |
16
|
|
|
private $inheritContext; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Route constructor. |
20
|
|
|
* |
21
|
|
|
* @param string $method |
22
|
|
|
* @param string $controller |
23
|
|
|
* @param array $context |
24
|
|
|
* @param bool $defaultContext |
25
|
|
|
* @param bool $inheritContext |
26
|
|
|
*/ |
27
|
2 |
|
public function __construct( |
28
|
|
|
$method, |
29
|
|
|
$controller, |
30
|
|
|
array $context, |
31
|
|
|
$defaultContext = true, |
32
|
|
|
$inheritContext = true |
33
|
|
|
) { |
34
|
2 |
|
$this->method = $method; |
35
|
2 |
|
$this->controller = $controller; |
36
|
2 |
|
$this->context = $context; |
37
|
2 |
|
$this->defaultContext = (bool)$defaultContext; |
38
|
2 |
|
$this->inheritContext = (bool)$inheritContext; |
39
|
2 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param boolean $defaultContext |
43
|
|
|
*/ |
44
|
|
|
public function setDefaultContext($defaultContext) |
45
|
|
|
{ |
46
|
|
|
$this->defaultContext = (bool)$defaultContext; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
2 |
|
public function getMethod() |
53
|
|
|
{ |
54
|
2 |
|
return $this->method; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $method |
59
|
|
|
*/ |
60
|
2 |
|
public function setMethod($method) |
61
|
|
|
{ |
62
|
2 |
|
$this->method = (string)$method; |
63
|
2 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string[] |
67
|
|
|
*/ |
68
|
2 |
|
public function getContext() |
69
|
|
|
{ |
70
|
2 |
|
return array_unique(array_merge($this->context, $this->includeDefaultContext() ? ['Default'] : [])); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array $context |
75
|
|
|
*/ |
76
|
|
|
public function setContext($context) |
77
|
|
|
{ |
78
|
|
|
$this->context = $context; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
2 |
|
public function includeDefaultContext() |
85
|
|
|
{ |
86
|
2 |
|
return $this->defaultContext || in_array('Default', $this->context, true); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
1 |
|
public function getController() |
93
|
|
|
{ |
94
|
1 |
|
return $this->controller; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $controller |
99
|
|
|
*/ |
100
|
|
|
public function setController($controller) |
101
|
|
|
{ |
102
|
|
|
$this->controller = $controller; |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
public function addContext($context) |
106
|
|
|
{ |
107
|
2 |
|
$this->context[] = $context; |
108
|
2 |
|
} |
109
|
|
|
|
110
|
|
|
/** @return bool */ |
111
|
2 |
|
public function inheritContext() |
112
|
|
|
{ |
113
|
2 |
|
return $this->inheritContext; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|