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