From dbcc26544a2d5377bcae1cbbb7a4c8e26ec873b6 Mon Sep 17 00:00:00 2001 From: camer0n Date: Wed, 29 Nov 2023 16:07:39 -0800 Subject: [PATCH] Issue #5120 - Reworked as object for increased flexibility. Some tweaking still to be done. --- class2.php | 14 ++-- e107_tests/tests/_data/e107_config.php.sample | 66 +++++++++++-------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/class2.php b/class2.php index 9c2c01efa..fadd6217a 100755 --- a/class2.php +++ b/class2.php @@ -143,7 +143,7 @@ $error_handler = new error_handler(); // // E: Setup other essential PHP parameters // -define('e107_INIT', true); +const e107_INIT = true; // DEPRECATED, use e107::getConfig() and e107::getPlugConfig() @@ -208,7 +208,7 @@ $tmp = e_ROOT.$HANDLERS_DIRECTORY; e107_require_once($tmp.'/e107_class.php'); unset($tmp); -if(empty($config['directories'])) // old e107_config.php format. +if(!class_exists('e107_config')) // old e107_config.php format. { $e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY','UPLOADS_DIRECTORY','SYSTEM_DIRECTORY', 'MEDIA_DIRECTORY','CACHE_DIRECTORY','LOGS_DIRECTORY', 'CORE_DIRECTORY', 'WEB_DIRECTORY'); $legacy_sql_info = compact('mySQLserver', 'mySQLuser', 'mySQLpassword', 'mySQLdefaultdb', 'mySQLprefix'); @@ -225,10 +225,10 @@ if(empty($config['directories'])) // old e107_config.php format. } else // New e107_config.php format. v2.4+ { - $e107_paths = $config['directories']; - $sql_info = $config['mySQL']; - $E107_CONFIG = $config['other'] ?? []; - unset($config); + $e107_paths = $config->paths(); + $sql_info = $config->database(); + $E107_CONFIG = $config->other() ?? []; + //unset($config); } @@ -1369,7 +1369,7 @@ function getperms($arg, $ap = null, $path = null) return true; } - if ($arg === 'P' && preg_match('#(.*?)/' .e107::getInstance()->getFolder('plugins'). '(.*?)/(.*?)#', $path, $matches)) + if ($arg === 'P' && preg_match('#(.*?)/' .e107::getFolder('plugins'). '(.*?)/(.*?)#', $path, $matches)) { $sql = e107::getDb('psql'); diff --git a/e107_tests/tests/_data/e107_config.php.sample b/e107_tests/tests/_data/e107_config.php.sample index 1ca9f08b1..31ffb628a 100644 --- a/e107_tests/tests/_data/e107_config.php.sample +++ b/e107_tests/tests/_data/e107_config.php.sample @@ -36,30 +36,44 @@ $SYSTEM_DIRECTORY = 'e107_system/'; $E107_CONFIG = array('site_path' => '000000test'); */ -define('e_MOD_REWRITE',true); +const e_MOD_REWRITE = true; -return [ - 'mySQL' => [ - 'server' => '{{ mySQLserver }}', - 'user' => '{{ mySQLuser }}', - 'password' => '{{ mySQLpassword }}', - 'defaultdb'=> '{{ mySQLdefaultdb }}', - 'prefix' => '{{ mySQLprefix }}', - 'charset' => 'utf8', - ], - 'directories' => [ // leave empty to use default - 'admin' => 'e107_admin/', - 'files' => 'e107_files/', - 'images' => 'e107_images/', - 'themes' => 'e107_themes/', - 'plugins' => 'e107_plugins/', - 'handlers' => 'e107_handlers/', - 'languages' => 'e107_languages/', - 'help' => 'e107_docs/help/', - 'system' => 'e107_system/', - 'media' => 'e107_media/', - ], - 'other' => [ - 'site_path' => '000000test' - ] -]; +class e107_config +{ + public function database() + { + return [ + 'server' => '{{ mySQLserver }}', + 'user' => '{{ mySQLuser }}', + 'password' => '{{ mySQLpassword }}', + 'defaultdb'=> '{{ mySQLdefaultdb }}', + 'prefix' => '{{ mySQLprefix }}', + 'charset' => 'utf8', + ]; + } + + public function paths() + { + return [ + 'admin' => 'e107_admin/', + 'files' => 'e107_files/', + 'images' => 'e107_images/', + 'themes' => 'e107_themes/', + 'plugins' => 'e107_plugins/', + 'handlers' => 'e107_handlers/', + 'languages' => 'e107_languages/', + 'help' => 'e107_docs/help/', + 'system' => 'e107_system/', + 'media' => 'e107_media/', + ]; + } + + public function other() + { + return [ + 'site_path' => '000000test' + ]; + } +} + +return new e107_config; \ No newline at end of file