From 607f7daf51f8053b60275265e291daf4a6dbd777 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 15 Dec 2018 02:46:08 -0500 Subject: [PATCH] Add PHP 5 compatible recursive dirname() --- boot.php | 19 +++++++++++++++++++ src/App.php | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 24e691279..222011f6b 100644 --- a/boot.php +++ b/boot.php @@ -854,3 +854,22 @@ function validate_include(&$file) // Simply return flag return $valid; } + +/** + * PHP 5 compatible dirname() with count parameter + * + * @see http://php.net/manual/en/function.dirname.php#113193 + * + * @deprecated with PHP 7 + * @param string $path + * @param int $levels + * @return string + */ +function rdirname($path, $levels = 1) +{ + if ($levels > 1) { + return dirname(rdirname($path, --$levels)); + } else { + return dirname($path); + } +} \ No newline at end of file diff --git a/src/App.php b/src/App.php index 45d743b0d..261c3e74c 100644 --- a/src/App.php +++ b/src/App.php @@ -523,7 +523,7 @@ class App if (!empty($relative_script_path)) { // Module if (!empty($_SERVER['QUERY_STRING'])) { - $path = trim(dirname($relative_script_path, substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); + $path = trim(rdirname($relative_script_path, substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); } else { // Root page $path = trim($relative_script_path, '/');