@@ -106,7 +106,7 @@ public function setRouter(Router $router)
106106 /**
107107 * Set request
108108 *
109- * @param Request $server
109+ * @param Request $request
110110 */
111111 public function setRequest (Request $ request )
112112 {
@@ -199,6 +199,11 @@ public function __call($name, $params)
199199 */
200200 protected function getSessionId ()
201201 {
202+ if ( ! $ this ->session )
203+ {
204+ return null ;
205+ }
206+
202207 $ sessionId = $ this ->session ->getId ();
203208
204209 // by default we provide only hashed version of session id
@@ -214,6 +219,11 @@ protected function getSessionId()
214219 */
215220 protected function getRouteName ()
216221 {
222+ if ( ! $ this ->router )
223+ {
224+ return null ;
225+ }
226+
217227 return $ this ->router ->getCurrentRoute ()->getName ();
218228 }
219229
@@ -224,6 +234,11 @@ protected function getRouteName()
224234 */
225235 protected function getUrl ()
226236 {
237+ if ( ! $ this ->request )
238+ {
239+ return null ;
240+ }
241+
227242 $ url = $ this ->request ->path ();
228243
229244 if ( ! starts_with ($ url , '/ ' ))
@@ -248,6 +263,11 @@ protected function getUrl()
248263 */
249264 protected function getRequestMethod ()
250265 {
266+ if ( ! $ this ->request )
267+ {
268+ return null ;
269+ }
270+
251271 return $ this ->request ->method ();
252272 }
253273
@@ -258,6 +278,11 @@ protected function getRequestMethod()
258278 */
259279 protected function getServerIp ()
260280 {
281+ if ( ! $ this ->request )
282+ {
283+ return null ;
284+ }
285+
261286 return $ this ->request ->server ->get ('SERVER_ADDR ' );
262287 }
263288
@@ -268,6 +293,11 @@ protected function getServerIp()
268293 */
269294 protected function getClientIp ()
270295 {
296+ if ( ! $ this ->request )
297+ {
298+ return null ;
299+ }
300+
271301 return $ this ->request ->getClientIp ();
272302 }
273303
@@ -278,6 +308,11 @@ protected function getClientIp()
278308 */
279309 protected function getClientUserAgent ()
280310 {
311+ if ( ! $ this ->request )
312+ {
313+ return null ;
314+ }
315+
281316 return $ this ->request ->server ->get ('HTTP_USER_AGENT ' );
282317 }
283318
@@ -299,6 +334,11 @@ protected function getEnvironment()
299334 */
300335 protected function getFromSession ($ key )
301336 {
337+ if ( ! $ this ->session )
338+ {
339+ return null ;
340+ }
341+
302342 return $ this ->session ->get ($ key );
303343 }
304344
0 commit comments