1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Saxulum\SaxulumControllerProvider\Map; |
4
|
|
|
|
5
|
|
|
class Controller |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var Map |
9
|
|
|
*/ |
10
|
|
|
protected $map; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $serviceId; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $namespace; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $injectContainer = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $injectionKeys = array(); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var Method[] |
34
|
|
|
*/ |
35
|
|
|
protected $methods = array(); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $controllerInfo |
39
|
|
|
*/ |
40
|
|
|
public function __construct(array $controllerInfo = null) |
41
|
|
|
{ |
42
|
|
|
if (!is_null($controllerInfo)) { |
43
|
|
|
$this->setServiceId($controllerInfo['serviceId']); |
44
|
|
|
$this->setNamespace($controllerInfo['namespace']); |
45
|
|
|
$this->setInjectContainer($controllerInfo['injectContainer']); |
46
|
|
|
$this->setInjectionKeys($controllerInfo['injectionKeys']); |
47
|
|
|
foreach ($controllerInfo['methods'] as $methodInfo) { |
48
|
|
|
$this->addMethod(new Method($methodInfo)); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Map $map |
55
|
|
|
* @param bool $stopPropagation |
56
|
|
|
* @return $this |
57
|
|
|
*/ |
58
|
|
|
public function setMap(Map $map, $stopPropagation = false) |
59
|
|
|
{ |
60
|
|
|
if (!$stopPropagation) { |
61
|
|
|
$map->addController($this, true); |
62
|
|
|
} |
63
|
|
|
$this->map = $map; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return Map |
70
|
|
|
*/ |
71
|
|
|
public function end() |
72
|
|
|
{ |
73
|
|
|
return $this->map; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param $serviceId |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
|
|
public function setServiceId($serviceId) |
81
|
|
|
{ |
82
|
|
|
$this->serviceId = $serviceId; |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getServiceId() |
91
|
|
|
{ |
92
|
|
|
return $this->serviceId; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $namespace |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function setNamespace($namespace) |
100
|
|
|
{ |
101
|
|
|
$this->namespace = $namespace; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getNamespace() |
110
|
|
|
{ |
111
|
|
|
return $this->namespace; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param boolean $injectContainer |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
|
|
public function setInjectContainer($injectContainer) |
119
|
|
|
{ |
120
|
|
|
$this->injectContainer = $injectContainer; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return boolean |
127
|
|
|
*/ |
128
|
|
|
public function isInjectContainer() |
129
|
|
|
{ |
130
|
|
|
return $this->injectContainer; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param array $injectionKeys |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
|
|
public function setInjectionKeys($injectionKeys) |
138
|
|
|
{ |
139
|
|
|
$this->injectionKeys = $injectionKeys; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
|
public function getInjectionKeys() |
148
|
|
|
{ |
149
|
|
|
return $this->injectionKeys; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
|
|
public function hasInjectionKeys() |
156
|
|
|
{ |
157
|
|
|
return $this->injectionKeys ? true : false; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param Method $method |
162
|
|
|
* @param bool $stopPropagation |
163
|
|
|
* @return Method |
164
|
|
|
*/ |
165
|
|
|
public function addMethod(Method $method = null, $stopPropagation = false) |
166
|
|
|
{ |
167
|
|
|
if (is_null($method)) { |
168
|
|
|
$method = new Method(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
if (!$stopPropagation) { |
172
|
|
|
$method->setController($this, true); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$this->methods[] = $method; |
176
|
|
|
|
177
|
|
|
return $method; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return Method[] |
182
|
|
|
*/ |
183
|
|
|
public function getMethods() |
184
|
|
|
{ |
185
|
|
|
return $this->methods; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return bool |
190
|
|
|
*/ |
191
|
|
|
public function hasMethods() |
192
|
|
|
{ |
193
|
|
|
return $this->methods ? true : false; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return array |
198
|
|
|
*/ |
199
|
|
|
public function __toArray() |
200
|
|
|
{ |
201
|
|
|
$controllerInfo = array(); |
202
|
|
|
$controllerInfo['serviceId'] = $this->getServiceId(); |
203
|
|
|
$controllerInfo['namespace'] = $this->getNamespace(); |
204
|
|
|
$controllerInfo['injectContainer'] = $this->isInjectContainer(); |
205
|
|
|
$controllerInfo['injectionKeys'] = $this->getInjectionKeys(); |
206
|
|
|
$controllerInfo['methods'] = array(); |
207
|
|
|
foreach ($this->getMethods() as $method) { |
208
|
|
|
$controllerInfo['methods'][] = $method->__toArray(); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
return $controllerInfo; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|