Url::add_url_handler(): accept null as $pattern to match the root on the application

This commit is contained in:
Benjamin Renard 2023-02-28 19:07:58 +01:00
parent 4ff9aa71ad
commit f16f433326
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
2 changed files with 5 additions and 2 deletions

View file

@ -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();

View file

@ -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) {