1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Http\Request\Traits; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class InteractsWithMca |
7
|
|
|
* @package Nip\Http\Request\Traits |
8
|
|
|
*/ |
9
|
|
|
trait InteractsWithMca |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Has the action been dispatched? |
13
|
|
|
* @var boolean |
14
|
|
|
*/ |
15
|
|
|
protected $dispatched = false; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Module |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $module; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Module key for retrieving module from params |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $moduleKey = 'module'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Controller |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $controller; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Controller key for retrieving controller from params |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $controllerKey = 'controller'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Action |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $action; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Action key for retrieving action from params |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $actionKey = 'action'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Retrieve the action key |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getActionKey() |
59
|
|
|
{ |
60
|
|
|
return $this->actionKey; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set the action key |
65
|
|
|
* |
66
|
|
|
* @param string $key |
67
|
|
|
* @return self |
68
|
|
|
*/ |
69
|
|
|
public function setActionKey($key) |
70
|
|
|
{ |
71
|
|
|
$this->actionKey = (string) $key; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public function hasMCA() |
80
|
|
|
{ |
81
|
|
|
return $this->getMCA() != '..'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getMCA() |
88
|
|
|
{ |
89
|
|
|
return $this->getModuleName() . '.' . $this->getControllerName() . '.' . $this->getActionName(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Retrieve the module name |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
1 |
|
public function getModuleName() |
97
|
|
|
{ |
98
|
1 |
|
if (null === $this->module) { |
99
|
|
|
$this->module = $this->attributes->get($this->getModuleKey()); |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
return $this->module; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Retrieve the module key |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function getModuleKey() |
111
|
|
|
{ |
112
|
|
|
return $this->moduleKey; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Set the module key |
117
|
|
|
* |
118
|
|
|
* @param string $key |
119
|
|
|
* @return $this |
120
|
|
|
*/ |
121
|
|
|
public function setModuleKey($key) |
122
|
|
|
{ |
123
|
|
|
$this->moduleKey = (string) $key; |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Retrieve the controller name |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
1 |
|
public function getControllerName() |
133
|
|
|
{ |
134
|
1 |
|
if ($this->controller === null) { |
135
|
|
|
$this->initControllerName(); |
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
return $this->controller; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function initControllerName() |
142
|
|
|
{ |
143
|
|
|
$this->controller = $this->attributes->get($this->getControllerKey()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Retrieve the controller key |
148
|
|
|
* |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function getControllerKey() |
152
|
|
|
{ |
153
|
|
|
return $this->controllerKey; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Set the controller key |
158
|
|
|
* |
159
|
|
|
* @param string $key |
160
|
|
|
* @return self |
161
|
|
|
*/ |
162
|
|
|
public function setControllerKey($key) |
163
|
|
|
{ |
164
|
|
|
$this->controllerKey = (string) $key; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Retrieve the action name |
171
|
|
|
* |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
1 |
|
public function getActionName() |
175
|
|
|
{ |
176
|
1 |
|
if (null === $this->action) { |
177
|
|
|
$this->setActionName($this->getActionDefault()); |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
return $this->action; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Set the action name |
185
|
|
|
* @param string $value |
186
|
|
|
* @return self |
187
|
|
|
*/ |
188
|
1 |
|
public function setActionName($value) |
189
|
|
|
{ |
190
|
1 |
|
if ($value) { |
191
|
1 |
|
$this->action = $value; |
192
|
|
|
} |
193
|
|
|
|
194
|
1 |
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
|
|
public function getActionDefault() |
201
|
|
|
{ |
202
|
|
|
return 'index'; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Set the controller name to use |
207
|
|
|
* |
208
|
|
|
* @param string $value |
209
|
|
|
* @return self |
210
|
|
|
*/ |
211
|
1 |
|
public function setControllerName($value) |
212
|
|
|
{ |
213
|
1 |
|
if ($value) { |
214
|
1 |
|
$this->controller = $value; |
215
|
|
|
} |
216
|
|
|
|
217
|
1 |
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Set the module name to use |
222
|
|
|
* @param string $value |
223
|
|
|
* @return self |
224
|
|
|
*/ |
225
|
1 |
|
public function setModuleName($value) |
226
|
|
|
{ |
227
|
1 |
|
if ($value) { |
228
|
1 |
|
$this->module = $value; |
229
|
|
|
} |
230
|
|
|
|
231
|
1 |
|
return $this; |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|