1
|
|
|
<?php |
2
|
|
|
namespace Fwlib\Web; |
3
|
|
|
|
4
|
|
|
use Fwlib\Base\SingletonTrait; |
5
|
|
|
use Fwlib\Util\UtilContainer; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Request content holder |
9
|
|
|
* |
10
|
|
|
* Content are cached as property. They can also be modified via setter, to |
11
|
|
|
* implement default module/action etc. |
12
|
|
|
* |
13
|
|
|
* @see \Fwlib\Web\RequestInterface |
14
|
|
|
* |
15
|
|
|
* @property string $actionParameter |
16
|
|
|
* @property string $moduleParameter |
17
|
|
|
* |
18
|
|
|
* @copyright Copyright 2015 Fwolf |
19
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ |
20
|
|
|
*/ |
21
|
|
|
trait RequestTrait |
22
|
|
|
{ |
23
|
|
|
use SingletonTrait; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $action = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $module = null; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @see RequestInterface::getAction() |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getAction() |
43
|
|
|
{ |
44
|
|
|
if (is_null($this->action)) { |
45
|
|
|
$this->action = UtilContainer::getInstance()->getHttp() |
|
|
|
|
46
|
|
|
->getGet($this->actionParameter); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $this->action; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @see RequestInterface::getActionParameter() |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getActionParameter() |
59
|
|
|
{ |
60
|
|
|
return $this->actionParameter; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @see RequestInterface::getModule() |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getModule() |
70
|
|
|
{ |
71
|
|
|
if (is_null($this->module)) { |
72
|
|
|
$this->module = UtilContainer::getInstance()->getHttp() |
|
|
|
|
73
|
|
|
->getGet($this->moduleParameter); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->module; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @see RequestInterface::getModuleParameter() |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getModuleParameter() |
86
|
|
|
{ |
87
|
|
|
return $this->moduleParameter; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @see RequestInterface::setAction() |
93
|
|
|
* |
94
|
|
|
* @param string $action |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
|
|
public function setAction($action) |
98
|
|
|
{ |
99
|
|
|
$this->action = $action; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @see RequestInterface::setActionParameter() |
107
|
|
|
* |
108
|
|
|
* @param string $param |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function setActionParameter($param) |
112
|
|
|
{ |
113
|
|
|
$this->actionParameter = $param; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @see RequestInterface::setModule() |
121
|
|
|
* |
122
|
|
|
* @param string $module |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function setModule($module) |
126
|
|
|
{ |
127
|
|
|
$this->module = $module; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @see RequestInterface::setModuleParameter() |
135
|
|
|
* |
136
|
|
|
* @param string $param |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
|
|
public function setModuleParameter($param) |
140
|
|
|
{ |
141
|
|
|
$this->moduleParameter = $param; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.