From 5e500d5cdeff59742c189c224a1c744afd26b671 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 8 Oct 2021 12:31:48 +0200 Subject: [PATCH] LSurl: expose current request as static class variable --- src/includes/class/class.LSurl.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/includes/class/class.LSurl.php b/src/includes/class/class.LSurl.php index a5b4c0e6..0dd06327 100644 --- a/src/includes/class/class.LSurl.php +++ b/src/includes/class/class.LSurl.php @@ -30,6 +30,9 @@ LSsession :: loadLSclass('LSlog_staticLoggerClass'); */ class LSurl extends LSlog_staticLoggerClass { + // Current request (defined at least current URL have been analyse by LSurl :: handle_request()) + public static $request = null; + /* * Configured URL patterns : * @@ -265,29 +268,34 @@ class LSurl extends LSlog_staticLoggerClass { * @retval void **/ public static function handle_request($default_url=null) { - $request = self :: get_request($default_url); + self :: $request = self :: get_request($default_url); - if (!is_callable($request -> handler)) { - self :: log_error("URL handler function ".$request -> handler."() does not exists !"); + if (!is_callable(self :: $request -> handler)) { + self :: log_error( + "URL handler function ".self :: $request -> handler."() does not exists !" + ); self :: log_fatal(_("This request could not be handled.")); } - if ($request -> api_mode) + if (self :: $request -> api_mode) LSsession :: setApiMode(); elseif (class_exists('LStemplate')) - LStemplate :: assign('request', $request); + LStemplate :: assign('request', self :: $request); // Check authentication (if need) - if($request -> authenticated && ! LSsession :: startLSsession()) { + if(self :: $request -> authenticated && ! LSsession :: startLSsession()) { LSsession :: displayTemplate(); return true; } try { - return call_user_func($request -> handler, $request); + return call_user_func(self :: $request -> handler, self :: $request); } catch (Exception $e) { - self :: log_exception($e, "An exception occured running URL handler function ".$request -> handler."()"); + self :: log_exception( + $e, "An exception occured running URL handler function ". + getCallableName(self :: $request -> handler) + ); self :: log_fatal(_("This request could not be processed correctly.")); } }