1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package application |
4
|
|
|
* @subpackage processors |
5
|
|
|
* @author marius orcsik <[email protected]> |
6
|
|
|
* @date 09.08.31 |
7
|
|
|
*/ |
8
|
|
|
namespace vsc\application\processors; |
9
|
|
|
|
10
|
|
|
use vsc\application\sitemaps\ClassMap; |
11
|
|
|
use vsc\application\sitemaps\MappingA; |
12
|
|
|
use vsc\domain\models\ModelA; |
13
|
|
|
use vsc\infrastructure\vsc; |
14
|
|
|
use vsc\infrastructure\BaseObject; |
15
|
|
|
use vsc\presentation\requests\HttpRequestA; |
16
|
|
|
use vsc\presentation\responses\HttpResponse; |
17
|
|
|
use vsc\presentation\responses\HttpResponseA; |
18
|
|
|
use vsc\application\dispatchers\RwDispatcher; |
19
|
|
|
|
20
|
|
|
abstract class ProcessorA extends BaseObject implements ProcessorInterface { |
21
|
|
|
private $oCurrentMap; |
22
|
|
|
protected $aLocalVars = array(); |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @returns ClassMap |
26
|
|
|
*/ |
27
|
3 |
|
public function getMap() { |
28
|
3 |
|
if (MappingA::isValid($this->oCurrentMap)) { |
29
|
2 |
|
return $this->oCurrentMap; |
30
|
|
|
} else { |
31
|
1 |
|
$oMirror = new \ReflectionClass($this); |
32
|
1 |
|
return new ClassMap($oMirror->getName(), '.*'); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param MappingA $oMap |
38
|
|
|
*/ |
39
|
10 |
|
public function setMap(MappingA $oMap) { |
40
|
10 |
|
$this->oCurrentMap = $oMap; |
41
|
10 |
|
$aTainted = $oMap->getTaintedVars(); |
42
|
10 |
|
if (is_array($aTainted) && count($aTainted) >= 1) { |
43
|
|
|
$this->setLocalVars($aTainted); |
44
|
|
|
} |
45
|
10 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
* @param array $aVars |
50
|
|
|
* @param bool $bPreserveKeys |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
1 |
|
public function setLocalVars($aVars = array(), $bPreserveKeys = false) { |
54
|
1 |
|
if ($bPreserveKeys) { |
55
|
1 |
|
$this->aLocalVars = array_merge($this->aLocalVars, $aVars); |
56
|
|
|
} else { |
57
|
|
|
// This needs improvement to take into account incoming arrays |
58
|
|
|
// containing both string keys - which exist or not in the $aLocalVars array |
59
|
|
|
// and numeric indexes |
60
|
|
|
foreach ($this->aLocalVars as $sKey => $sValue) { |
61
|
|
|
$this->aLocalVars[$sKey] = array_shift($aVars); |
62
|
|
|
} |
63
|
|
|
} |
64
|
1 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
1 |
|
public function getLocalVars() { |
70
|
1 |
|
return $this->aLocalVars; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $sVar |
75
|
|
|
* @param string $sValue |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
2 |
|
public function setVar($sVar, $sValue) { |
79
|
2 |
|
if (array_key_exists($sVar, $this->aLocalVars)) { |
80
|
1 |
|
$this->aLocalVars[$sVar] = $sValue; |
81
|
1 |
|
return true; |
82
|
|
|
} |
83
|
1 |
|
return false; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $sVar |
88
|
|
|
* @return null |
89
|
|
|
*/ |
90
|
1 |
|
public function getVar($sVar) { |
91
|
1 |
|
if (array_key_exists($sVar, $this->aLocalVars)) { |
92
|
1 |
|
return $this->aLocalVars[$sVar]; |
93
|
|
|
} else { |
94
|
|
|
return null; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* |
100
|
|
|
* @see ProcessorI::delegateRequest() |
101
|
|
|
* @param HttpRequestA $oHttpRequest |
102
|
|
|
* @param ProcessorA $oNewProcessor |
103
|
|
|
* @param HttpResponseA $oResponse |
|
|
|
|
104
|
|
|
* @returns ModelA |
105
|
|
|
*/ |
106
|
1 |
|
public function delegateRequest(HttpRequestA $oHttpRequest, ProcessorA $oNewProcessor, HttpResponseA $oResponse = null) { |
|
|
|
|
107
|
1 |
|
$oDispatcher = vsc::getEnv()->getDispatcher(); |
108
|
|
|
/** @var ClassMap $oMap */ |
109
|
1 |
|
$oMap = $oDispatcher->getSiteMap()->findProcessorMap($oNewProcessor); |
110
|
|
|
|
111
|
1 |
|
if (MappingA::isValid($oMap)) { |
112
|
1 |
|
$oNewProcessor->setMap($oMap); |
113
|
1 |
|
$oNewProcessor->init(); |
114
|
|
|
|
115
|
|
|
/* @var RwDispatcher $oDispatcher */ |
116
|
1 |
|
$oMap->merge($this->getMap()); |
117
|
|
|
|
118
|
1 |
|
if (HttpResponse::isValid($oResponse)) { |
119
|
|
|
$oMap->setResponse($oResponse); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
|
$this->setMap($oMap); |
123
|
|
|
} |
124
|
1 |
|
$oNewProcessor->setLocalVars($this->getLocalVars(), true); |
125
|
|
|
|
126
|
1 |
|
return $oNewProcessor->handleRequest($oHttpRequest); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|