From 23ef7cd52c2955dd511257e8d0b61d62514b1d3b Mon Sep 17 00:00:00 2001 From: Steven Ngesera Date: Wed, 22 Nov 2023 01:32:56 +0200 Subject: [PATCH] comment updated and phpunit tests updated --- index.php | 3 --- lib/dispatch.php | 2 +- lib/environment.php | 23 ----------------------- modules/2fa/2fa.ini | 2 +- modules/api_login/api.php | 7 ++++--- modules/carddav_contacts/carddav.ini | 2 +- modules/contacts/modules.php | 2 +- modules/dynamic_login/dynamic_login.ini | 2 +- modules/github/github.ini | 2 +- modules/hello_world/modules.php | 2 +- modules/hello_world/setup.php | 4 ++-- modules/hello_world/site.js | 2 +- modules/imap/oauth2.ini | 2 +- modules/ldap_contacts/ldap.ini | 2 +- modules/recaptcha/recaptcha.ini | 2 +- modules/site/lib.php | 7 +++---- modules/themes/themes.ini | 2 +- modules/wordpress/wordpress.ini | 2 +- scripts/config_gen.php | 3 --- scripts/create_account.php | 3 ++- scripts/delete_account.php | 5 +++-- scripts/update_password.php | 3 +-- tests/phpunit/config.php | 6 +++--- tests/phpunit/data/app.php | 3 +++ tests/phpunit/dispatch.php | 4 ++-- tests/phpunit/request.php | 2 +- 26 files changed, 37 insertions(+), 62 deletions(-) create mode 100644 tests/phpunit/data/app.php diff --git a/index.php b/index.php index e9e29ef56d..c67456bb9b 100644 --- a/index.php +++ b/index.php @@ -26,9 +26,6 @@ error_reporting(E_ALL | E_STRICT); } -/* config file location */ -define('CONFIG_FILE', APP_PATH.'hm3.rc'); - /* don't let anything output content until we are ready */ ob_start(); diff --git a/lib/dispatch.php b/lib/dispatch.php index 4bd3b83214..2dca2cd270 100644 --- a/lib/dispatch.php +++ b/lib/dispatch.php @@ -171,7 +171,7 @@ class Hm_Dispatch { */ public function __construct($config) { - /* get the site config defined in the hm3.rc file */ + /* get the site config defined in the config/app.php file */ $this->site_config = $config; /* check for the site module set override */ diff --git a/lib/environment.php b/lib/environment.php index 5c4d99f956..2d451dbe63 100644 --- a/lib/environment.php +++ b/lib/environment.php @@ -60,29 +60,6 @@ protected function get_environment_variables() { } } -if (!function_exists('config_env_file')) { - /** - * Get / set the specified configuration value. - * - * If an array is passed as the key, we will assume you want to set an array of values. - * - * @param array|string|null $key - * @param mixed $default - * @return mixed - */ - function config_env_file($key = null, $default = null) { - if (is_null($key)) { - // TO DO - } - - if (is_array($key)) { - // TO DO - } - // TO DO - // return ConfigClass->get($key, $default); - } -} - if (!function_exists('env')) { /** * Gets the value of an environment variable. diff --git a/modules/2fa/2fa.ini b/modules/2fa/2fa.ini index c9c0bea11c..f037d9b581 100644 --- a/modules/2fa/2fa.ini +++ b/modules/2fa/2fa.ini @@ -1,7 +1,7 @@ ; Constants used for 2 factor authentication with Google Authenticator ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/api_login/api.php b/modules/api_login/api.php index 3f05ae165a..23d948a0f8 100644 --- a/modules/api_login/api.php +++ b/modules/api_login/api.php @@ -10,7 +10,6 @@ define('APP_PATH', dirname(dirname(dirname(__FILE__))).'/'); define('VENDOR_PATH', APP_PATH.'vendor/'); define('WEB_ROOT', ''); -define('CONFIG_FILE', APP_PATH.'hm3.rc'); /* Init the framework */ require_once APP_PATH.'lib/framework.php'; @@ -29,7 +28,8 @@ function cypht_login($user, $pass, $url, $lifetime=0) { $session->check($request, $user, $pass, false); if ($session->is_active()) { list($domain, $path, $secure) = url_parse($url); - $config = new Hm_Site_Config_File(CONFIG_FILE); + $all_configs = merge_config_files(APP_PATH.'config'); + $config = new Hm_Site_Config_File($all_configs); $user_config = load_user_config_object($config); $user_config->load($user, $pass); module_init_functions($user_config, $session, $request, $config, $user, $pass); @@ -93,7 +93,8 @@ function url_parse($url) { * @return array */ function session_init() { - $config = new Hm_Site_Config_File(APP_PATH.'hm3.rc'); + $all_configs = merge_config_files(APP_PATH.'config'); + $config = new Hm_Site_Config_File($all_configs); $module_exec = new Hm_Module_Exec($config); $module_exec->load_module_sets('functional_api'); $request = new Hm_Request($module_exec->filters, $config); diff --git a/modules/carddav_contacts/carddav.ini b/modules/carddav_contacts/carddav.ini index 87788908c9..ef74bf3721 100644 --- a/modules/carddav_contacts/carddav.ini +++ b/modules/carddav_contacts/carddav.ini @@ -1,7 +1,7 @@ ; Constants used for CardDav communication ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/contacts/modules.php b/modules/contacts/modules.php index d3032e0f40..d85fefadc7 100644 --- a/modules/contacts/modules.php +++ b/modules/contacts/modules.php @@ -154,7 +154,7 @@ class Hm_Output_contacts_list extends Hm_Output_Module { protected function output() { if (count($this->get('contact_sources', array())) == 0) { return '
'.$this->trans('No contact backends are enabled!'). - '
'.$this->trans('At least one backend must be enabled in the hm3.ini file to use contacts.').'
'; + '
'.$this->trans('At least one backend must be enabled in the config/app.php file to use contacts.').''; } $per_page = 25; $current_page = $this->get('contact_page', 1); diff --git a/modules/dynamic_login/dynamic_login.ini b/modules/dynamic_login/dynamic_login.ini index 4f745f6f0d..7692967a48 100644 --- a/modules/dynamic_login/dynamic_login.ini +++ b/modules/dynamic_login/dynamic_login.ini @@ -1,7 +1,7 @@ ; Constants used for dynamic login configuration ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/github/github.ini b/modules/github/github.ini index eca36addc2..edd1f826c3 100644 --- a/modules/github/github.ini +++ b/modules/github/github.ini @@ -1,7 +1,7 @@ ; Constants used for oauth2 communication with github.com ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/hello_world/modules.php b/modules/hello_world/modules.php index 5d66a2b6d7..fb054cbd44 100644 --- a/modules/hello_world/modules.php +++ b/modules/hello_world/modules.php @@ -8,7 +8,7 @@ * This module set is intented to give developers an overview of * the module system. Most of what it does is silly and consists of printing "Hello * World" in different ways. You can enable this module by adding it to the modules - * value in the hm3.ini file, and rebuilding the site config. + * value in the config/app.php file. */ /** diff --git a/modules/hello_world/setup.php b/modules/hello_world/setup.php index 69c0d62ee7..9fd26c2ba0 100644 --- a/modules/hello_world/setup.php +++ b/modules/hello_world/setup.php @@ -6,7 +6,7 @@ * This module set is intented to give developers an overview of * the module system. Most of what it does is silly and consists of printing "Hello * World" in different ways. You can enable this module by adding it to the modules - * value in the hm3.ini file, and rebuilding the site config. + * value in the config/app.php file. */ /** @@ -20,7 +20,7 @@ * These set the default sources for modules assigned in this file. It can be overridden * by the module assignment itself. The module system uses the source to know which PHP * files to include when servicing a given request. It should match the name of the module - * set as used in the hm3.ini file, as well as the current directory name. + * set as used in the config/app.php file, as well as the current directory name. */ handler_source('hello_world'); output_source('hello_world'); diff --git a/modules/hello_world/site.js b/modules/hello_world/site.js index 84e329ba79..7f5356ac9b 100644 --- a/modules/hello_world/site.js +++ b/modules/hello_world/site.js @@ -6,7 +6,7 @@ * way to delay actions until page onload if you need to. Built in data sources like * hm_page_name() are defined before this is run so they are also available. When the * site build process is run this code will be combined with JS from other module sets, - * and optionally minified based on the hm3.ini file settings. + * and optionally minified based on the config/app.php file settings. */ /** diff --git a/modules/imap/oauth2.ini b/modules/imap/oauth2.ini index 2226538b09..d708b945a3 100644 --- a/modules/imap/oauth2.ini +++ b/modules/imap/oauth2.ini @@ -1,7 +1,7 @@ ; Constants used for oauth2 authentication over IMAP ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/ldap_contacts/ldap.ini b/modules/ldap_contacts/ldap.ini index 4d40f4b558..65f68646d6 100644 --- a/modules/ldap_contacts/ldap.ini +++ b/modules/ldap_contacts/ldap.ini @@ -1,7 +1,7 @@ ; Constants used for LDAP communication ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/recaptcha/recaptcha.ini b/modules/recaptcha/recaptcha.ini index f3c3d2c7bb..82d11502ad 100644 --- a/modules/recaptcha/recaptcha.ini +++ b/modules/recaptcha/recaptcha.ini @@ -3,7 +3,7 @@ ; https://developers.google.com/recaptcha/ ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/site/lib.php b/modules/site/lib.php index 62bff62750..73e4a5c68e 100644 --- a/modules/site/lib.php +++ b/modules/site/lib.php @@ -2,13 +2,12 @@ /** * To use these overrides, you must first enable the "site" module in your - * hm3.ini file, then rebuild your configuration with the config_gen.php script - * to activate the module. + * config/app.php file to activate the module. */ /** * Override the session class. These are the methods that must be overriden to - * create a new session backend. The "session_type" value in your hm3.ini must + * create a new session backend. The "session_type" value in your config/app.php must * be set to "custom" to activate this class. There are several other * properties and methods that can be modified to create custom sessions: * @@ -103,7 +102,7 @@ public function destroy($request) { /** * Override the authentication class. This method needs to be overriden to * create a custom authentication backend. You must set the "auth_type" setting - * in your hm3.ini file to "custom" to activate this class. More information + * in your config/app.php file to "custom" to activate this class. More information * about the base class for authentication is located here: * * https://cypht.org/docs/code_docs/class-Hm_Auth.html diff --git a/modules/themes/themes.ini b/modules/themes/themes.ini index ca166aaab8..dae93edae4 100644 --- a/modules/themes/themes.ini +++ b/modules/themes/themes.ini @@ -1,7 +1,7 @@ ; Custom themes available in Cypht ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. You will also need to re-run the ; config_gen.php script. ; ; SECURITY ALERT ! MAKE SURE THAT THIS FILE IS NOT ACCESSIBLE BY THE BROWSER ! diff --git a/modules/wordpress/wordpress.ini b/modules/wordpress/wordpress.ini index 2b654c0e42..3bf33af7ed 100644 --- a/modules/wordpress/wordpress.ini +++ b/modules/wordpress/wordpress.ini @@ -1,7 +1,7 @@ ; Constants used for oauth2 communication with WordPress.com ; ; Once you edit this file, you must move it to the directory defined by -; app_data_dir in your hm3.ini file. You will also need to re-run the +; app_data_dir in your config/app.php file. No need to re-run the ; config_gen.php script. ; ; diff --git a/scripts/config_gen.php b/scripts/config_gen.php index 43a7fe5e90..06d6e165c0 100644 --- a/scripts/config_gen.php +++ b/scripts/config_gen.php @@ -130,9 +130,6 @@ function build_config() { /* combine and compress page content */ $hashes = combine_includes($js, $js_compress, $css, $css_compress, $settings); - /* write out the hm3.rc file */ - write_config_file($settings, $filters); - /* create the production version */ create_production_site($assets, $settings, $hashes); } diff --git a/scripts/create_account.php b/scripts/create_account.php index c9fa0ee757..aafe6af6b0 100644 --- a/scripts/create_account.php +++ b/scripts/create_account.php @@ -26,8 +26,9 @@ /* get the framework */ require APP_PATH.'lib/framework.php'; +$all_configs = merge_config_files(APP_PATH.'config'); /* get config object */ -$config = new Hm_Site_Config_File(APP_PATH.'hm3.rc'); +$config = new Hm_Site_Config_File($all_configs); /* check config for db auth */ if ($config->get('auth_type') != 'DB') { diff --git a/scripts/delete_account.php b/scripts/delete_account.php index 639ab9cdf1..0c3c41d38d 100644 --- a/scripts/delete_account.php +++ b/scripts/delete_account.php @@ -24,9 +24,10 @@ /* get the framework */ require APP_PATH.'lib/framework.php'; - +//get all config array merged +$all_configs = merge_config_files(APP_PATH.'config'); /* get config object */ -$config = new Hm_Site_Config_File(APP_PATH.'hm3.rc'); +$config = new Hm_Site_Config_File($all_configs); /* check config for db auth */ if ($config->get('auth_type') != 'DB') { diff --git a/scripts/update_password.php b/scripts/update_password.php index 9f6a15ac78..6ff209b449 100644 --- a/scripts/update_password.php +++ b/scripts/update_password.php @@ -25,9 +25,8 @@ /* get the framework */ require APP_PATH.'lib/framework.php'; - /* get config object */ -$config = new Hm_Site_Config_File(APP_PATH.'hm3.rc'); +$config = new Hm_Site_Config_File(merge_config_files(APP_PATH.'config')); /* check config for db auth */ if ($config->get('auth_type') != 'DB') { diff --git a/tests/phpunit/config.php b/tests/phpunit/config.php index 101a39695a..5a1e7dd5bf 100644 --- a/tests/phpunit/config.php +++ b/tests/phpunit/config.php @@ -171,7 +171,7 @@ public function setUp(): void { * @runInSeparateProcess */ public function test_get_modules() { - $config = new Hm_Site_Config_File('./data/siteconfig.rc'); + $config = new Hm_Site_Config_File(merge_config_files(APP_PATH.'tests/phpunit/data')); $this->assertFalse($config->get_modules()); $config->set('modules', 'asdf'); $this->assertEquals(array('asdf'), $config->get_modules()); @@ -181,7 +181,7 @@ public function test_get_modules() { * @runInSeparateProcess */ public function test_site_load() { - $config = new Hm_Site_Config_File(APP_PATH.'tests/phpunit/data/siteconfig.rc'); + $config = new Hm_Site_Config_File(merge_config_files(APP_PATH.'tests/phpunit/data')); $this->assertEquals(array('version' => VERSION, 'foo' => 'bar', 'default_setting_foo' => 'bar'), $config->dump()); } /** @@ -189,7 +189,7 @@ public function test_site_load() { * @runInSeparateProcess */ public function test_get_user_defaults() { - $config = new Hm_Site_Config_File(APP_PATH.'tests/phpunit/data/siteconfig.rc'); + $config = new Hm_Site_Config_File(merge_config_files(APP_PATH.'tests/phpunit/data')); $this->assertEquals(array('version' => VERSION, 'foo' => 'bar', 'default_setting_foo' => 'bar'), $config->dump()); } public function tearDown(): void { diff --git a/tests/phpunit/data/app.php b/tests/phpunit/data/app.php new file mode 100644 index 0000000000..0653c8f16c --- /dev/null +++ b/tests/phpunit/data/app.php @@ -0,0 +1,3 @@ + 'bar','default_setting_foo' => 'bar',); \ No newline at end of file diff --git a/tests/phpunit/dispatch.php b/tests/phpunit/dispatch.php index 90cee9da37..a115c0052c 100644 --- a/tests/phpunit/dispatch.php +++ b/tests/phpunit/dispatch.php @@ -7,7 +7,7 @@ class Hm_Test_Dispatch extends TestCase { public function setUp(): void { require 'bootstrap.php'; require 'helpers.php'; - define('CONFIG_FILE', APP_PATH.'hm3.rc'); + define('CONFIG_FILE', merge_config_files(APP_PATH.'config')); $this->config = new Hm_Mock_Config(); } /** @@ -142,7 +142,7 @@ class Hm_Test_Debug_Page_Redirect extends TestCase { public function setUp(): void { define('DEBUG_MODE', true); require 'bootstrap.php'; - define('CONFIG_FILE', APP_PATH.'hm3.rc'); + define('CONFIG_FILE', merge_config_files(APP_PATH.'config')); } /** * @preserveGlobalState disabled diff --git a/tests/phpunit/request.php b/tests/phpunit/request.php index be019855ff..8f3c66b1ab 100644 --- a/tests/phpunit/request.php +++ b/tests/phpunit/request.php @@ -9,7 +9,7 @@ class Hm_Test_Request extends TestCase { public function setUp(): void { require 'bootstrap.php'; - define('CONFIG_FILE', APP_PATH.'hm3.rc'); + define('CONFIG_FILE', merge_config_files(APP_PATH.'config')); $this->config = new Hm_Mock_Config(); } /**