1 | <?php |
||
56 | class Context |
||
57 | { |
||
58 | const STATE_ERROR = -1; |
||
59 | const STATE_INIT = 0; |
||
60 | const STATE_READY = 1; |
||
61 | const STATE_EXECUTED = 2; |
||
62 | const STATE_DONE = 3; |
||
63 | |||
64 | /** |
||
65 | * Client request |
||
66 | * |
||
67 | * @var Request |
||
68 | */ |
||
69 | protected $request; |
||
70 | |||
71 | /** |
||
72 | * Reponse to be sent to client |
||
73 | * |
||
74 | * @var Response |
||
75 | */ |
||
76 | protected $response; |
||
77 | |||
78 | /** |
||
79 | * Current state |
||
80 | * |
||
81 | * @var integer |
||
82 | */ |
||
83 | protected $state = self::STATE_INIT; |
||
84 | |||
85 | /** |
||
86 | * Description of current error |
||
87 | * |
||
88 | * @var string |
||
89 | */ |
||
90 | protected $error; |
||
91 | |||
92 | /** |
||
93 | * Action's result returned by executed method |
||
94 | * (recommended: string) |
||
95 | * |
||
96 | * @var mixed |
||
97 | */ |
||
98 | protected $result; |
||
99 | |||
100 | /** |
||
101 | * The parent context (if any) |
||
102 | * |
||
103 | * @var Context |
||
104 | */ |
||
105 | protected $parent; |
||
106 | |||
107 | /** |
||
108 | * The action name |
||
109 | * |
||
110 | * @var string |
||
111 | */ |
||
112 | protected $actionName; |
||
113 | |||
114 | /** |
||
115 | * Constructor |
||
116 | * |
||
117 | * @param Request $request Client's request |
||
118 | * @param Response $response Pre-defined return response |
||
|
|||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | 37 | public function __construct(Request $request, Response $response = null) |
|
127 | |||
128 | /** |
||
129 | * Returns client's request |
||
130 | * |
||
131 | * @return Request |
||
132 | */ |
||
133 | 26 | public function getRequest() |
|
137 | |||
138 | /** |
||
139 | * Returns Response if defined or null otherwise |
||
140 | * |
||
141 | * @return Response |
||
142 | */ |
||
143 | 23 | public function getResponse() |
|
147 | |||
148 | /** |
||
149 | * Returns parent context (if any) |
||
150 | * |
||
151 | * @return Context |
||
152 | */ |
||
153 | 1 | public function getParent() |
|
157 | |||
158 | /** |
||
159 | * Defines a parent Context |
||
160 | * |
||
161 | * This usually happends when running multiples actions within a same |
||
162 | * request (modules, widgets ...) |
||
163 | * |
||
164 | * @param Context $context The parent context |
||
165 | * |
||
166 | * @return void |
||
167 | */ |
||
168 | 1 | public function setParent(Context $context) |
|
172 | |||
173 | /** |
||
174 | * Tells if a parent context is defined |
||
175 | * |
||
176 | * @return boolean |
||
177 | */ |
||
178 | 6 | public function hasParent() |
|
182 | |||
183 | /** |
||
184 | * Returns a new parent Context |
||
185 | * |
||
186 | * @return Context |
||
187 | */ |
||
188 | 1 | public function newParent() |
|
195 | |||
196 | /** |
||
197 | * Tells if this context is ready (Action name is defined) |
||
198 | * |
||
199 | * @return boolean |
||
200 | */ |
||
201 | 26 | public function isReady() |
|
205 | |||
206 | /** |
||
207 | * Tells if this context encountered an error |
||
208 | * |
||
209 | * @return boolean |
||
210 | */ |
||
211 | 3 | public function isError() |
|
215 | |||
216 | /** |
||
217 | * Tells if the context has been executed |
||
218 | * |
||
219 | * @return boolean |
||
220 | */ |
||
221 | 1 | public function isExecuted() |
|
225 | |||
226 | /** |
||
227 | * Tells if the context has ended execution and client's response |
||
228 | * has been defined |
||
229 | * |
||
230 | * @return boolean |
||
231 | */ |
||
232 | 23 | public function isDone() |
|
236 | |||
237 | /** |
||
238 | * Sets a description of the error and toggle error state |
||
239 | * |
||
240 | * @param string $description Error description |
||
241 | * |
||
242 | * @see ContextEvents::ERROR |
||
243 | * @return void |
||
244 | */ |
||
245 | 5 | public function setError($description) |
|
250 | |||
251 | /** |
||
252 | * Returns the error description (if any) |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | 1 | public function getError() |
|
260 | |||
261 | /** |
||
262 | * Sets state to executed and store result |
||
263 | * |
||
264 | * @param mixed $result Action's result (recommended: string) |
||
265 | * |
||
266 | * @see ContextEvents::EXECUTED |
||
267 | * @return void |
||
268 | */ |
||
269 | 24 | public function setResult($result) |
|
274 | |||
275 | /** |
||
276 | * Defines response and sets state to Done. |
||
277 | * |
||
278 | * @param Response $response Client response |
||
279 | * |
||
280 | * @see ContextEvents::RESPONSE |
||
281 | * @return void |
||
282 | */ |
||
283 | 18 | public function setResponse(Response $response) |
|
288 | |||
289 | /** |
||
290 | * |
||
291 | * @return integer |
||
292 | */ |
||
293 | 2 | public function getState() |
|
297 | |||
298 | /** |
||
299 | * |
||
300 | * @return mixed |
||
301 | */ |
||
302 | 10 | public function getResult() |
|
306 | |||
307 | 26 | public function getActionName() |
|
311 | |||
312 | 28 | public function setActionName($actionName) |
|
323 | } |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.