1 | <?php |
||
45 | class WebRequest extends RequestAbstract |
||
46 | { |
||
47 | /** |
||
48 | * @access protected |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $_requestedUrl; |
||
52 | |||
53 | /** |
||
54 | * @access protected |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $_headers; |
||
58 | |||
59 | /** |
||
60 | * @access protected |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $_protocol; |
||
64 | |||
65 | /** |
||
66 | * @access protected |
||
67 | * @var boolean |
||
68 | */ |
||
69 | protected $_isSsl = false; |
||
70 | |||
71 | /** |
||
72 | * @access protected |
||
73 | * @var \Zepi\Turbo\FrameworkInterface\SessionInterface |
||
74 | */ |
||
75 | protected $_session = null; |
||
76 | |||
77 | /** |
||
78 | * Constructs the object |
||
79 | * |
||
80 | * @access public |
||
81 | * @param string $requestedUrl |
||
82 | * @param string $route |
||
83 | * @param array params |
||
84 | * @param string $base |
||
85 | * @param string $locale |
||
86 | * @param boolean $isSsl |
||
87 | * @param array $headers |
||
88 | * @param string $protocol |
||
89 | * @param array $data |
||
90 | */ |
||
91 | public function __construct($requestedUrl, $route, $params, $base, $locale, $isSsl, $headers, $protocol, $data = array()) |
||
100 | |||
101 | /** |
||
102 | * Returns the requested url |
||
103 | * |
||
104 | * @access public |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getRequestedUrl() |
||
111 | |||
112 | /** |
||
113 | * Returns the delimitier, which is used to split the route |
||
114 | * into parts. |
||
115 | * The delimiter for the html request is the slash (/). |
||
116 | * |
||
117 | * @access public |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getRouteDelimiter() |
||
124 | |||
125 | /** |
||
126 | * Saves the given value for the given key in the session data |
||
127 | * |
||
128 | * @access public |
||
129 | * @param string $key |
||
130 | * @param mixed $value |
||
131 | */ |
||
132 | public function setSessionData($key, $value) |
||
136 | |||
137 | /** |
||
138 | * Returns the session value of the given key. |
||
139 | * |
||
140 | * @access public |
||
141 | * @param string $key |
||
142 | * @return mixed |
||
143 | */ |
||
144 | public function getSessionData($key = '') |
||
152 | |||
153 | /** |
||
154 | * Deletes the value for the given key |
||
155 | * |
||
156 | * @access public |
||
157 | * @param string $key |
||
158 | * @return boolean |
||
159 | */ |
||
160 | public function deleteSessionData($key) |
||
169 | |||
170 | /** |
||
171 | * Removes all session data |
||
172 | * |
||
173 | * @access public |
||
174 | */ |
||
175 | public function clearSessionData() |
||
181 | |||
182 | /** |
||
183 | * Returns the cookie value of the given key. |
||
184 | * |
||
185 | * @access public |
||
186 | * @param string $key |
||
187 | * @return mixed |
||
188 | */ |
||
189 | public function getCookieData($key = '') |
||
197 | |||
198 | /** |
||
199 | * Returns true if this request was made over a |
||
200 | * secure connection trough ssl. |
||
201 | * |
||
202 | * @access public |
||
203 | * @return boolean |
||
204 | */ |
||
205 | public function isSsl() |
||
209 | |||
210 | /** |
||
211 | * Adds a session object to the request |
||
212 | * |
||
213 | * @access public |
||
214 | * @param \Zepi\Turbo\FrameworkInterface\SessionInterface $session |
||
215 | * @return boolean |
||
216 | */ |
||
217 | public function setSession(SessionInterface $session) |
||
227 | |||
228 | /** |
||
229 | * Returns true if a session for the given name |
||
230 | * exists. Otherwise returns false. |
||
231 | * |
||
232 | * @access public |
||
233 | * @return boolean |
||
234 | */ |
||
235 | public function hasSession() |
||
243 | |||
244 | /** |
||
245 | * Returns the session |
||
246 | * |
||
247 | * @access public |
||
248 | * @return false|\Zepi\Turbo\FrameworkInterface\SessionInterface |
||
249 | */ |
||
250 | public function getSession() |
||
258 | |||
259 | /** |
||
260 | * Removes the session |
||
261 | * |
||
262 | * @access public |
||
263 | */ |
||
264 | public function removeSession() |
||
269 | |||
270 | /** |
||
271 | * Returns the value for the given header key |
||
272 | * |
||
273 | * @access public |
||
274 | * @param string $key |
||
275 | * @return false|mixed |
||
276 | */ |
||
277 | public function getHeader($key) |
||
285 | |||
286 | /** |
||
287 | * Returns an array with all headers |
||
288 | * |
||
289 | * @access public |
||
290 | * @return array |
||
291 | */ |
||
292 | public function getHeaders() |
||
296 | |||
297 | /** |
||
298 | * Returns the protocol of the request |
||
299 | * |
||
300 | * @access public |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getProtocol() |
||
307 | } |
||
308 |
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: