@@ -21,12 +21,12 @@ class RequestStack extends Nette\Object implements Nette\Http\IRequest
2121{
2222
2323 /**
24- * @var array|Nette\Http\IRequest
24+ * @var array|Nette\Http\IRequest[]
2525 */
2626 private $ requests = [];
2727
2828 /**
29- * @var Nette\Http\IRequest
29+ * @var Nette\Http\IRequest|NULL
3030 */
3131 private $ current ;
3232
@@ -41,7 +41,24 @@ public function pushRequest(Nette\Http\IRequest $request)
4141
4242
4343 /**
44- * @return Nette\Http\IRequest
44+ * @return Nette\Http\IRequest|null
45+ */
46+ public function popRequest ()
47+ {
48+ if (count ($ this ->requests ) === 0 ) {
49+ return NULL ;
50+ }
51+
52+ $ head = array_pop ($ this ->requests );
53+ $ current = end ($ this ->requests );
54+ $ this ->current = ($ current !== FALSE ) ? $ current : NULL ;
55+ return $ head ;
56+ }
57+
58+
59+
60+ /**
61+ * @return Nette\Http\IRequest|NULL
4562 */
4663 public function getCurrentRequest ()
4764 {
@@ -55,7 +72,7 @@ public function getCurrentRequest()
5572 */
5673 public function getUrl ()
5774 {
58- return $ this ->current -> getUrl ();
75+ return $ this ->current !== NULL ? $ this -> current -> getUrl () : NULL ;
5976 }
6077
6178
@@ -66,10 +83,10 @@ public function getUrl()
6683 public function getQuery ($ key = NULL , $ default = NULL )
6784 {
6885 if (func_num_args () === 0 ) {
69- return $ this ->current -> getQuery ();
86+ return $ this ->current !== NULL ? $ this -> current -> getQuery () : [] ;
7087 }
7188
72- return $ this ->current -> getQuery ($ key , $ default );
89+ return $ this ->current !== NULL ? $ this -> current -> getQuery ($ key , $ default ) : NULL ;
7390 }
7491
7592
@@ -80,10 +97,10 @@ public function getQuery($key = NULL, $default = NULL)
8097 public function getPost ($ key = NULL , $ default = NULL )
8198 {
8299 if (func_num_args () === 0 ) {
83- return $ this ->current -> getPost ();
100+ return $ this ->current !== NULL ? $ this -> current -> getPost () : [] ;
84101 }
85102
86- return $ this ->current -> getPost ($ key , $ default );
103+ return $ this ->current !== NULL ? $ this -> current -> getPost ($ key , $ default ) : NULL ;
87104 }
88105
89106
@@ -93,7 +110,7 @@ public function getPost($key = NULL, $default = NULL)
93110 */
94111 public function getFile ($ key )
95112 {
96- return $ this ->current -> getFile ($ key );
113+ return $ this ->current !== NULL ? $ this -> current -> getFile ($ key ) : NULL ;
97114 }
98115
99116
@@ -103,7 +120,7 @@ public function getFile($key)
103120 */
104121 public function getFiles ()
105122 {
106- return $ this ->current -> getFiles ();
123+ return $ this ->current !== NULL ? $ this -> current -> getFiles () : [] ;
107124 }
108125
109126
@@ -113,7 +130,7 @@ public function getFiles()
113130 */
114131 public function getCookie ($ key , $ default = NULL )
115132 {
116- return $ this ->current -> getCookie ($ key , $ default );
133+ return $ this ->current !== NULL ? $ this -> current -> getCookie ($ key , $ default ) : NULL ;
117134 }
118135
119136
@@ -123,7 +140,7 @@ public function getCookie($key, $default = NULL)
123140 */
124141 public function getCookies ()
125142 {
126- return $ this ->current -> getCookies ();
143+ return $ this ->current !== NULL ? $ this -> current -> getCookies () : [] ;
127144 }
128145
129146
@@ -133,7 +150,7 @@ public function getCookies()
133150 */
134151 public function getMethod ()
135152 {
136- return $ this ->current -> getMethod ();
153+ return $ this ->current !== NULL ? $ this -> current -> getMethod () : NULL ;
137154 }
138155
139156
@@ -143,7 +160,7 @@ public function getMethod()
143160 */
144161 public function isMethod ($ method )
145162 {
146- return $ this ->current -> isMethod ($ method );
163+ return $ this ->current !== NULL ? $ this -> current -> isMethod ($ method ) : FALSE ;
147164 }
148165
149166
@@ -153,7 +170,7 @@ public function isMethod($method)
153170 */
154171 public function getHeader ($ header , $ default = NULL )
155172 {
156- return $ this ->current -> getHeader ($ header , $ default );
173+ return $ this ->current !== NULL ? $ this -> current -> getHeader ($ header , $ default ) : NULL ;
157174 }
158175
159176
@@ -163,7 +180,7 @@ public function getHeader($header, $default = NULL)
163180 */
164181 public function getHeaders ()
165182 {
166- return $ this ->current -> getHeaders ();
183+ return $ this ->current !== NULL ? $ this -> current -> getHeaders () : [] ;
167184 }
168185
169186
@@ -173,7 +190,7 @@ public function getHeaders()
173190 */
174191 public function isSecured ()
175192 {
176- return $ this ->current -> isSecured ();
193+ return $ this ->current !== NULL ? $ this -> current -> isSecured () : FALSE ;
177194 }
178195
179196
@@ -183,7 +200,7 @@ public function isSecured()
183200 */
184201 public function isAjax ()
185202 {
186- return $ this ->current -> isAjax ();
203+ return $ this ->current !== NULL ? $ this -> current -> isAjax () : FALSE ;
187204 }
188205
189206
@@ -193,7 +210,7 @@ public function isAjax()
193210 */
194211 public function getRemoteAddress ()
195212 {
196- return $ this ->current -> getRemoteAddress ();
213+ return $ this ->current !== NULL ? $ this -> current -> getRemoteAddress () : NULL ;
197214 }
198215
199216
@@ -203,7 +220,7 @@ public function getRemoteAddress()
203220 */
204221 public function getRemoteHost ()
205222 {
206- return $ this ->current -> getRemoteHost ();
223+ return $ this ->current !== NULL ? $ this -> current -> getRemoteHost () : NULL ;
207224 }
208225
209226
@@ -213,7 +230,7 @@ public function getRemoteHost()
213230 */
214231 public function getRawBody ()
215232 {
216- return $ this ->current -> getRawBody ();
233+ return $ this ->current !== NULL ? $ this -> current -> getRawBody () : NULL ;
217234 }
218235
219236
@@ -226,19 +243,20 @@ public function getRawBody()
226243 */
227244 public function detectLanguage (array $ langs )
228245 {
229- if ( $ this ->current instanceof Nette \Http \Request) {
230- return $ this ->current ->detectLanguage ($ langs );
231- }
246+ return $ this ->current instanceof Nette \Http \Request
247+ ? $ this ->current ->detectLanguage ($ langs )
248+ : NULL ;
232249 }
233250
234251
235252
236253 /**
237- * @return Url|null
254+ * @return Url|NULL
238255 */
239256 public function getReferer ()
240257 {
241- return ($ url = $ this ->getHeader ('referer ' )) ? new Url ($ url ) : NULL ;
258+ $ url = $ this ->getHeader ('referer ' );
259+ return $ url !== NULL ? new Url ($ url ) : NULL ;
242260 }
243261
244262}
0 commit comments