1 | <?php |
||
45 | class WebRequest extends RequestAbstract |
||
46 | { |
||
47 | const METHOD_GET = 'GET'; |
||
48 | const METHOD_POST = 'POST'; |
||
49 | const METHOD_PUT = 'PUT'; |
||
50 | const METHOD_DELETE = 'DELETE'; |
||
51 | |||
52 | /** |
||
53 | * @access protected |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $_method; |
||
57 | |||
58 | /** |
||
59 | * @access protected |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $_requestedUrl; |
||
63 | |||
64 | /** |
||
65 | * @access protected |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $_headers; |
||
69 | |||
70 | /** |
||
71 | * @access protected |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $_protocol; |
||
75 | |||
76 | /** |
||
77 | * @access protected |
||
78 | * @var boolean |
||
79 | */ |
||
80 | protected $_isSsl = false; |
||
81 | |||
82 | /** |
||
83 | * @access protected |
||
84 | * @var \Zepi\Turbo\FrameworkInterface\SessionInterface |
||
85 | */ |
||
86 | protected $_session = null; |
||
87 | |||
88 | /** |
||
89 | * Constructs the object |
||
90 | * |
||
91 | * @access public |
||
92 | * @param string $method |
||
93 | * @param string $requestedUrl |
||
94 | * @param string $route |
||
95 | * @param array params |
||
96 | * @param string $base |
||
97 | * @param string $locale |
||
98 | * @param boolean $isSsl |
||
99 | * @param array $headers |
||
100 | * @param string $protocol |
||
101 | * @param array $data |
||
102 | */ |
||
103 | public function __construct($method, $requestedUrl, $route, $params, $base, $locale, $isSsl, $headers, $protocol, $data = array()) |
||
113 | |||
114 | /** |
||
115 | * Returns the method of the request |
||
116 | * |
||
117 | * @access public |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getMethod() |
||
124 | |||
125 | /** |
||
126 | * Returns the requested url |
||
127 | * |
||
128 | * @access public |
||
129 | * @return string |
||
130 | */ |
||
131 | public function getRequestedUrl() |
||
135 | |||
136 | /** |
||
137 | * Returns the delimitier, which is used to split the route |
||
138 | * into parts. |
||
139 | * The delimiter for the html request is the slash (/). |
||
140 | * |
||
141 | * @access public |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getRouteDelimiter() |
||
148 | |||
149 | /** |
||
150 | * Saves the given value for the given key in the session data |
||
151 | * |
||
152 | * @access public |
||
153 | * @param string $key |
||
154 | * @param mixed $value |
||
155 | */ |
||
156 | public function setSessionData($key, $value) |
||
160 | |||
161 | /** |
||
162 | * Returns the session value of the given key. |
||
163 | * |
||
164 | * @access public |
||
165 | * @param string $key |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function getSessionData($key = '') |
||
176 | |||
177 | /** |
||
178 | * Deletes the value for the given key |
||
179 | * |
||
180 | * @access public |
||
181 | * @param string $key |
||
182 | * @return boolean |
||
183 | */ |
||
184 | public function deleteSessionData($key) |
||
193 | |||
194 | /** |
||
195 | * Removes all session data |
||
196 | * |
||
197 | * @access public |
||
198 | */ |
||
199 | public function clearSessionData() |
||
205 | |||
206 | /** |
||
207 | * Returns the cookie value of the given key. |
||
208 | * |
||
209 | * @access public |
||
210 | * @param string $key |
||
211 | * @return mixed |
||
212 | */ |
||
213 | public function getCookieData($key = '') |
||
221 | |||
222 | /** |
||
223 | * Returns true if this request was made over a |
||
224 | * secure connection trough ssl. |
||
225 | * |
||
226 | * @access public |
||
227 | * @return boolean |
||
228 | */ |
||
229 | public function isSsl() |
||
233 | |||
234 | /** |
||
235 | * Adds a session object to the request |
||
236 | * |
||
237 | * @access public |
||
238 | * @param \Zepi\Turbo\FrameworkInterface\SessionInterface $session |
||
239 | * @return boolean |
||
240 | */ |
||
241 | public function setSession(SessionInterface $session) |
||
251 | |||
252 | /** |
||
253 | * Returns true if a session for the given name |
||
254 | * exists. Otherwise returns false. |
||
255 | * |
||
256 | * @access public |
||
257 | * @return boolean |
||
258 | */ |
||
259 | public function hasSession() |
||
267 | |||
268 | /** |
||
269 | * Returns the session |
||
270 | * |
||
271 | * @access public |
||
272 | * @return false|\Zepi\Turbo\FrameworkInterface\SessionInterface |
||
273 | */ |
||
274 | public function getSession() |
||
282 | |||
283 | /** |
||
284 | * Removes the session |
||
285 | * |
||
286 | * @access public |
||
287 | */ |
||
288 | public function removeSession() |
||
293 | |||
294 | /** |
||
295 | * Returns the value for the given header key |
||
296 | * |
||
297 | * @access public |
||
298 | * @param string $key |
||
299 | * @return false|mixed |
||
300 | */ |
||
301 | public function getHeader($key) |
||
309 | |||
310 | /** |
||
311 | * Returns an array with all headers |
||
312 | * |
||
313 | * @access public |
||
314 | * @return array |
||
315 | */ |
||
316 | public function getHeaders() |
||
320 | |||
321 | /** |
||
322 | * Returns the protocol of the request |
||
323 | * |
||
324 | * @access public |
||
325 | * @return string |
||
326 | */ |
||
327 | public function getProtocol() |
||
331 | } |
||
332 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: