From 3edf176dc26b7f7dacf7911f9309d438ee48ec5e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sat, 25 Feb 2023 05:03:19 +0100 Subject: [PATCH] Url: store current request in a public static class variable to allow access from everywhere --- src/Url.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Url.php b/src/Url.php index 8a0659f..36875b5 100644 --- a/src/Url.php +++ b/src/Url.php @@ -6,6 +6,12 @@ use Exception; class Url { + /** + * Current request + * @var UrlRequest|null + */ + public static $request = null; + /** * Configured URL patterns : * @@ -426,31 +432,31 @@ class Url { public static function handle_request($default_url=null) { $sentry_span = new SentrySpan('http.handle_request', 'Handle the HTTP request'); - $request = self :: get_request($default_url); + self :: $request = self :: get_request($default_url); - if (!is_callable($request -> handler)) { + if (!is_callable(self :: $request -> handler)) { Log :: error( "URL handler function %s does not exists !", - format_callable($request -> handler)); + format_callable(self :: $request -> handler)); Log :: fatal(I18n::_("This request cannot be processed.")); } - if ($request -> api_mode) + if (self :: $request -> api_mode) self :: $_api_mode = true; if (Tpl :: initialized()) - Tpl :: assign('request', $request); + Tpl :: assign('request', self :: $request ); // Check authentication (if need) - if($request -> authenticated && !Auth::login(true)) + if(self :: $request -> authenticated && !Auth::login(true)) Log :: fatal(I18n::_("Authentication required but fail to authenticate you.")); try { - call_user_func($request -> handler, $request); + call_user_func(self :: $request -> handler, self :: $request ); } catch (Exception $e) { Log :: exception( - $e, "An exception occured running URL handler function %s()", - format_callable($request -> handler)); + $e, "An exception occured running URL handler %s", + format_callable(self :: $request -> handler)); Log :: fatal(I18n::_("This request could not be processed correctly.")); } $sentry_span->finish();