|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package application |
|
4
|
|
|
* @subpackage sitemaps |
|
5
|
|
|
* @author marius orcisk <[email protected]> |
|
6
|
|
|
* @date 09.11.29 |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace vsc\application\sitemaps; |
|
9
|
|
|
|
|
10
|
|
|
use vsc\application\controllers\ExceptionController; |
|
11
|
|
|
use vsc\infrastructure\urls\Url; |
|
12
|
|
|
use vsc\infrastructure\urls\UrlParserA; |
|
13
|
|
|
use vsc\infrastructure\Base; |
|
14
|
|
|
use vsc\infrastructure\BaseObject; |
|
15
|
|
|
use vsc\presentation\requests\HttpAuthenticationA; |
|
16
|
|
|
|
|
17
|
|
|
abstract class MappingA extends BaseObject { |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $sRegex; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $sPath; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $sTemplate; |
|
30
|
|
|
/** |
|
31
|
|
|
* the local template path - will be used to compose something like |
|
32
|
|
|
* this->sViewPath . view->typeOfView . this->sTemplate |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $sViewPath; |
|
37
|
|
|
|
|
38
|
|
|
private $bIsStatic = false; |
|
39
|
|
|
|
|
40
|
|
|
private $aControllerMaps = array(); |
|
41
|
|
|
|
|
42
|
|
|
private $aTaintedVars = []; |
|
43
|
|
|
|
|
44
|
|
|
private $sMatchingUrl; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var int |
|
48
|
|
|
*/ |
|
49
|
|
|
private $iAuthenticationType = null; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param MappingA $oMap |
|
53
|
|
|
*/ |
|
54
|
|
|
abstract protected function mergeResources($oMap); |
|
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
abstract public function getTitle(); |
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $sTitle |
|
61
|
|
|
*/ |
|
62
|
|
|
abstract public function setTitle($sTitle); |
|
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $sPath |
|
65
|
|
|
* @param string $sRegex |
|
66
|
|
|
*/ |
|
67
|
24 |
|
public function __construct($sPath, $sRegex) { |
|
68
|
24 |
|
$this->sPath = $sPath; |
|
69
|
24 |
|
$this->sRegex = $sRegex; |
|
70
|
24 |
|
} |
|
71
|
|
|
|
|
72
|
20 |
|
public function getRegex() { |
|
73
|
20 |
|
return $this->sRegex; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param bool $bStatic |
|
78
|
|
|
*/ |
|
79
|
2 |
|
public function setIsStatic($bStatic) { |
|
80
|
2 |
|
$this->bIsStatic = $bStatic; |
|
81
|
2 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
2 |
|
public function isStatic() { |
|
87
|
2 |
|
return $this->bIsStatic; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param MappingA $oMap |
|
92
|
|
|
*/ |
|
93
|
21 |
|
protected function mergePaths($oMap) { |
|
94
|
21 |
|
$sParentPath = $oMap->getTemplatePath(); |
|
95
|
21 |
|
if (!is_null($sParentPath) && is_null($this->getTemplatePath())) { |
|
96
|
1 |
|
$this->setTemplatePath($sParentPath); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
21 |
|
$sParentTemplate = $oMap->getTemplate(); |
|
100
|
21 |
|
if (!is_null($sParentTemplate) && is_null($this->getTemplate())) { |
|
101
|
|
|
$this->setTemplate($sParentTemplate); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
21 |
|
if (($this instanceof ContentTypeMappingInterface) && ($oMap instanceof ContentTypeMappingInterface)) { |
|
105
|
|
|
/** @var ContentTypeMappingInterface $oMap */ |
|
106
|
20 |
|
$sParentMainTemplatePath = $oMap->getMainTemplatePath(); |
|
107
|
20 |
|
if (is_null($this->getMainTemplatePath())) { |
|
|
|
|
|
|
108
|
1 |
|
$this->setMainTemplatePath($sParentMainTemplatePath); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
20 |
|
$sParentMainTemplate = $oMap->getMainTemplate(); |
|
111
|
20 |
|
if (is_null($this->getMainTemplate())) { |
|
|
|
|
|
|
112
|
1 |
|
$this->setMainTemplate($sParentMainTemplate); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
21 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param MappingA $oMap |
|
|
|
|
|
|
119
|
|
|
* @return $this |
|
120
|
|
|
*/ |
|
121
|
21 |
|
public function merge($oMap = null) { |
|
122
|
21 |
|
if (MappingA::isValid($oMap)) { |
|
123
|
21 |
|
$this->mergeResources($oMap); |
|
|
|
|
|
|
124
|
21 |
|
$this->mergePaths($oMap); |
|
|
|
|
|
|
125
|
|
|
// maybe I should merge the regexes too like processor_regex . '.*' . controller_regex |
|
126
|
|
|
|
|
127
|
21 |
|
$sTitle = $this->getTitle(); |
|
128
|
21 |
|
$sMapTitle = $oMap->getTitle(); |
|
|
|
|
|
|
129
|
21 |
|
if (empty($sTitle) && !empty($sMapTitle)) { |
|
130
|
|
|
$this->setTitle($sMapTitle); |
|
131
|
|
|
} |
|
132
|
21 |
|
$this->iAuthenticationType |= $oMap->getAuthenticationType(); |
|
133
|
|
|
} |
|
134
|
21 |
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param string $sPath |
|
139
|
|
|
* @return bool |
|
|
|
|
|
|
140
|
|
|
* @throws ExceptionSitemap |
|
141
|
|
|
*/ |
|
142
|
21 |
|
public function setTemplatePath($sPath) { |
|
143
|
21 |
|
$this->sViewPath = $this->getValidPath($sPath); |
|
144
|
21 |
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return string |
|
148
|
|
|
*/ |
|
149
|
21 |
|
public function getTemplatePath() { |
|
150
|
21 |
|
return $this->sViewPath; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param string $sPath |
|
155
|
|
|
*/ |
|
156
|
18 |
|
public function setTemplate($sPath) { |
|
157
|
18 |
|
$this->sTemplate = $sPath; |
|
158
|
18 |
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
19 |
|
public function getTemplate() { |
|
164
|
19 |
|
return $this->sTemplate; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return string |
|
169
|
|
|
*/ |
|
170
|
24 |
|
public function getPath() { |
|
171
|
24 |
|
return $this->sPath; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @deprecated |
|
176
|
|
|
* @param string $sRegex |
|
177
|
|
|
* @param string $sPath |
|
|
|
|
|
|
178
|
|
|
* @throws ExceptionController |
|
179
|
|
|
* @throws ExceptionSitemap |
|
180
|
|
|
* @returns ClassMap |
|
181
|
|
|
*/ |
|
182
|
|
|
public function mapController($sRegex, $sPath = null) { |
|
183
|
|
|
return $this->map($sRegex, $sPath); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $sRegex |
|
189
|
|
|
* @param string $sPath |
|
|
|
|
|
|
190
|
|
|
* @throws ExceptionController |
|
191
|
|
|
* @throws ExceptionSitemap |
|
192
|
|
|
* @returns ClassMap |
|
193
|
|
|
*/ |
|
194
|
22 |
|
public function map($sRegex, $sPath = null) { |
|
195
|
22 |
|
if (empty($sRegex)) { |
|
196
|
|
|
throw new ExceptionSitemap('An URI must be present.'); |
|
197
|
|
|
} |
|
198
|
22 |
|
if (is_null($sPath)) { |
|
199
|
|
|
// if we only have one parameter, we treat it as a path |
|
200
|
1 |
|
$sPath = $sRegex; |
|
201
|
1 |
|
$sRegex = $this->getRegex(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
22 |
|
$sKey = $sRegex; |
|
205
|
22 |
|
if (array_key_exists($sKey, $this->aControllerMaps)) { |
|
206
|
|
|
unset($this->aControllerMaps[$sKey]); |
|
207
|
|
|
} |
|
208
|
22 |
|
if (ClassMap::isValidMap($sPath)) { |
|
209
|
|
|
// instead of a path we have a namespace |
|
210
|
21 |
|
$oNewMap = new ClassMap($sPath, $sKey); |
|
211
|
21 |
|
$oNewMap->setModuleMap($this); |
|
212
|
21 |
|
$oNewMap->merge($this); |
|
213
|
|
|
|
|
214
|
21 |
|
$this->aControllerMaps[$sKey] = $oNewMap; |
|
215
|
|
|
|
|
216
|
21 |
|
return $oNewMap; |
|
217
|
|
|
} |
|
218
|
1 |
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* @return MappingA[] |
|
222
|
|
|
*/ |
|
223
|
20 |
|
public function getControllerMaps() { |
|
224
|
20 |
|
return $this->aControllerMaps; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @param string[] $aVars |
|
229
|
|
|
*/ |
|
230
|
18 |
|
public function setTaintedVars($aVars) { |
|
231
|
18 |
|
$this->aTaintedVars = $aVars; |
|
232
|
18 |
|
} |
|
233
|
|
|
|
|
234
|
10 |
|
public function getTaintedVars() { |
|
235
|
10 |
|
return $this->aTaintedVars; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param string $sUrl |
|
240
|
|
|
*/ |
|
241
|
19 |
|
public function setUrl($sUrl) { |
|
242
|
19 |
|
$this->sMatchingUrl = $sUrl; |
|
243
|
19 |
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @returns Url |
|
247
|
|
|
*/ |
|
248
|
2 |
|
public function getUrl() { |
|
249
|
2 |
|
$sRegex = '#(' . str_replace('#', '\#', $this->getRegex()) . ')#iUu'; |
|
250
|
2 |
|
$bHaveMatch = preg_match($sRegex, $this->sMatchingUrl, $aMatches); |
|
251
|
|
|
|
|
252
|
2 |
|
if ($bHaveMatch) { |
|
253
|
2 |
|
$url = new Url(); |
|
254
|
2 |
|
$url->setPath($aMatches[0]); |
|
255
|
2 |
|
return $url; |
|
256
|
|
|
} else { |
|
257
|
|
|
return new Base(); |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
2 |
|
public function setAuthenticationType($iAuthenticationType) { |
|
262
|
2 |
|
$this->iAuthenticationType = $iAuthenticationType; |
|
263
|
2 |
|
} |
|
264
|
|
|
|
|
265
|
22 |
|
public function getAuthenticationType() { |
|
266
|
22 |
|
return $this->iAuthenticationType; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @return string |
|
|
|
|
|
|
271
|
|
|
*/ |
|
272
|
1 |
|
public function getValidAuthenticationSchemas() { |
|
273
|
1 |
|
return HttpAuthenticationA::getAuthenticationSchemas($this->iAuthenticationType); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @return bool |
|
278
|
|
|
*/ |
|
279
|
2 |
|
public function requiresAuthentication() { |
|
280
|
2 |
|
return ($this->iAuthenticationType != HttpAuthenticationA::NONE); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @param Object $mappedObject |
|
285
|
|
|
* @return boolean |
|
286
|
|
|
*/ |
|
287
|
1 |
|
public function maps(BaseObject $mappedObject) |
|
288
|
|
|
{ |
|
289
|
1 |
|
return (bool)stristr(get_class($mappedObject), substr(basename($this->getPath()), 0, -4)); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @param string $sPath |
|
294
|
|
|
* @return string |
|
295
|
|
|
* @throws ExceptionSitemap |
|
296
|
|
|
*/ |
|
297
|
21 |
|
protected function getValidPath($sPath) { |
|
298
|
21 |
|
if (!is_dir($sPath)) { |
|
299
|
2 |
|
if (!ModuleMap::isValid($this) && !ModuleMap::isValid($this->getModuleMap())) { |
|
|
|
|
|
|
300
|
|
|
throw new ExceptionSitemap('No reference module path to use for relative paths'); |
|
301
|
|
|
} |
|
302
|
2 |
|
$sPath = $this->getModulePath() . $sPath; |
|
|
|
|
|
|
303
|
|
|
} |
|
304
|
21 |
|
$sPath = realpath($sPath); |
|
305
|
21 |
|
if (!is_dir($sPath)) { |
|
306
|
|
|
throw new ExceptionSitemap('Template path is not valid.'); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
21 |
|
return $sPath . DIRECTORY_SEPARATOR; |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.