From f16f433326ca1315a8cabfbfd0735da87deabbec Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 28 Feb 2023 19:07:58 +0100 Subject: [PATCH] Url::add_url_handler(): accept null as $pattern to match the root on the application --- src/App.php | 2 +- src/Url.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index c043f86..19a043a 100644 --- a/src/App.php +++ b/src/App.php @@ -68,7 +68,7 @@ class App { Tpl :: init(); if (self :: get('url.enabled', true, 'bool')) { Url::init(); - Url :: add_url_handler('#^$#', array('EesyPHP\\App', 'handle_homepage')); + Url :: add_url_handler(null, array('EesyPHP\\App', 'handle_homepage')); } if (Auth :: enabled()) { Auth :: init(); diff --git a/src/Url.php b/src/Url.php index 3e1d91b..29cd74b 100644 --- a/src/Url.php +++ b/src/Url.php @@ -79,7 +79,8 @@ class Url { /** * Add an URL pattern * - * @param string|array $pattern The URL pattern or an array of patterns (required) + * @param string|array|null $pattern The URL pattern, an array of patterns or null to + * match to the root of the application * @param callable $handler The URL pattern handler (must be callable, required) * @param array|null $additional_info Array of information to pass to the URL handler * @param boolean $authenticated Permit to define if this URL is accessible only for @@ -118,6 +119,8 @@ class Url { ) $error = true; return !$error; } + else if (is_null($pattern)) + $pattern = '#^$#'; $error = false; foreach($http_methods as $http_method) {