From 3377ccc5ea2b0839cdb2506ecccc3b18cfb26d33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 15 Feb 2023 21:40:30 +0100 Subject: [PATCH] Continued: - added method FrameworkConfiguration::isEnabled() which requires configuration keys like 'is_foo_enabled' while you can just invoke $configInstance->isEnabled('foo') - Added some debug lines - added missing configuration entries - Configuration entries like is__captcha_secured_enabled are still missing --- application/tests/config-local.php-dist | 40 +++++++++++ framework/config-global.php | 71 ++++++++++++++----- .../config/class_FrameworkConfiguration.php | 36 ++++++++++ .../classes/class_BaseFrameworkSystem.php | 2 +- .../class_CachedLocalFileDatabase.php | 2 +- .../feature/class_FrameworkFeature.php | 21 +++++- .../validator/class_EmailValidatorFilter.php | 2 +- ...ass_GraphicalCodeCaptchaVerifierFilter.php | 6 +- .../html/blocks/class_HtmlBlockHelper.php | 2 +- .../html/forms/class_HtmlFormHelper.php | 28 ++++---- .../console/class_DebugConsoleOutput.php | 6 +- .../rng/class_RandomNumberGenerator.php | 4 +- .../tools/console/class_ConsoleTools.php | 2 +- ...TestConfigurationLoadableClassesFilter.php | 11 +-- 14 files changed, 184 insertions(+), 49 deletions(-) create mode 100644 application/tests/config-local.php-dist diff --git a/application/tests/config-local.php-dist b/application/tests/config-local.php-dist new file mode 100644 index 00000000..7bb585dd --- /dev/null +++ b/application/tests/config-local.php-dist @@ -0,0 +1,40 @@ + + * @version 0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Some hub-specific configuration like port hostname where we will listen, etc. +$cfg = FrameworkBootstrap::getConfigurationInstance(); diff --git a/framework/config-global.php b/framework/config-global.php index 1daa27d5..fbf68496 100644 --- a/framework/config-global.php +++ b/framework/config-global.php @@ -277,9 +277,6 @@ $cfg->setConfigEntry('hash_extra_mask', '%1s:%2s:%3s'); // 1=salt, 2=extra salt, // CFG: HASH-NORMAL-MASK $cfg->setConfigEntry('hash_normal_mask', '%1s:%2s'); // 1=salt, 2=plain password/string -// CFG: IS-SINGLE-SERVER -$cfg->setConfigEntry('is_single_server', 'Y'); - // CFG: POST-REGISTRATION-CLASS $cfg->setConfigEntry('post_registration_class', 'Org\Mxchange\CoreFramework\Action\PostRegistration\Login\LoginAfterRegistrationAction'); @@ -301,12 +298,6 @@ $cfg->setConfigEntry('cookie_domain', FrameworkBootstrap::detectDomain()); // Is // CFG: COOKIE-SSL $cfg->setConfigEntry('cookie_ssl', FrameworkBootstrap::isHttpSecured()); -// CFG: CRYPT-FIXED-SALT -$cfg->setConfigEntry('crypt_fixed_salt', 'N'); - -// CFG: DB-UPDATE-PRIMARY-FORCED -$cfg->setConfigEntry('db_update_primary_forced', 'Y'); - // CFG: GERMAN-DATE-TIME $cfg->setConfigEntry('german_date_time', "%3\$s.%2\$s.%1\$s, %4\$s:%5\$s:%6\$s"); @@ -331,11 +322,11 @@ $cfg->setConfigEntry('local_file_database_class', 'Org\Mxchange\CoreFramework\Da // CFG: COMPRESSOR-CHANNEL-CLASS $cfg->setConfigEntry('compressor_channel_class', 'Org\Mxchange\CoreFramework\Middleware\Compressor\CompressorChannel'); -// CFG: DEBUG-HTML-OUTPUT-TIMINGS -$cfg->setConfigEntry('debug_html_output_timings', 'N'); +// CFG: IS-DEBUG-HTML-OUTPUT-TIMINGS-ENABLED +$cfg->setConfigEntry('is_debug_html_output_timings_enabled', false); -// CFG: DEBUG-CONSOLE-OUTPUT-TIMINGS -$cfg->setConfigEntry('debug_console_output_timings', 'Y'); +// CFG: IS-DEBUG-CONSOLE-OUTPUT-TIMINGS-ENABLED +$cfg->setConfigEntry('is_debug_console_output_timings_enabled', true); // CFG: PROXY-HOST $cfg->setConfigEntry('proxy_host', ''); @@ -349,9 +340,6 @@ $cfg->setConfigEntry('proxy_username', ''); // CFG: PROXY-PASSWORD $cfg->setConfigEntry('proxy_password', ''); -// CFG: PROXY-CONNECT-METHOD -$cfg->setConfigEntry('proxy_connect_method', 'Y'); - // CFG: HOSTNAME-FILE $cfg->setConfigEntry('hostname_file', '/etc/hostname'); @@ -483,3 +471,54 @@ $cfg->setConfigEntry('developer_mode_enabled', true); // CFG: CRYPTO-HASH-FUNCTION-NAME $cfg->setConfigEntry('crypto_hash_function_name', 'sha256'); + +/** + * ------------------------------------------------------------- + * Boolean is_*_enabled configuration keys + * ------------------------------------------------------------- + */ + +// CFG: IS-REGISTER-EMAIL-UNIQUE-ENABLED +$cfg->setConfigEntry('is_register_email_unique_enabled', true); + +// CFG: IS-BLOCK-SHOWS-REGISTRATION-ENABLED +$cfg->setConfigEntry('is_block_shows_registration_enabled', true); + +// CFG: IS-REGISTER-REQUIRES-EMAIl-ENABLED +$cfg->setConfigEntry('is_register_requires_email_enabled', true); + +// CFG: IS-REGISTER-INCLUDES-PROFILE-ENABLED +$cfg->setConfigEntry('is_register_includes_profile_enabled', true); + +// CFG: IS-REGISTER-PERSONAL-DATA-ENABLED +$cfg->setConfigEntry('is_register_personal_data_enabled', true); + +// CFG: IS-PROFILE-INCLUDES-BIRTHDAY-ENABLED +$cfg->setConfigEntry('is_profile_includes_birthday_enabled', true); + +// CFG: IS-USER-LOGIN-ENABLED +$cfg->setConfigEntry('is_user_login_enabled', true); + +// CFG: IS-GUEST-LOGIN-ENABLED +$cfg->setConfigEntry('is_guest_login_enabled', true); + +// CFG: IS-EMAIL-CHANGE-CONFIRMATION-ENABLED +$cfg->setConfigEntry('is_email_change_confirmation_enabled', true); + +// CFG: IS-EMAIL-CHANGE-ENABLED +$cfg->setConfigEntry('is_email_change_enabled', true); + +// CFG: IS-REFILL-PAGE-ACTIVE-ENABLED +$cfg->setConfigEntry('is_refill_page_active_enabled', true); + +// CFG: IS-PROXY-CONNECT-METHOD-ENABLED +$cfg->setConfigEntry('is_proxy_connect_method_enabled', true); + +// CFG: IS-SINGLE-SERVER-ENABLED +$cfg->setConfigEntry('is_single_server_enabled', true); + +// CFG: IS-CRYPT-FIXED-SALT-ENABLED +$cfg->setConfigEntry('is_crypt_fixed_salt_enabled', false); + +// CFG: IS-DB-UPDATE-PRIMARY-FORCED-ENABLED +$cfg->setConfigEntry('is_db_update_primary_forced_enabled', true); diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index 7375aa04..b4696e1b 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils; // Import SPL stuff use \InvalidArgumentException; +use \UnexpectedValueException; /** * A class for the configuration stuff implemented in a singleton design pattern @@ -221,6 +222,41 @@ class FrameworkConfiguration implements Registerable { //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } + /** + * Checks if a configuration entry is_*_enabled set to 'Y' + * + * @param $keyPart Configuration to expand with is_$keyPart_enabled + * @return $enabled Whether it has been set to Y or N + * @throws InvalidArgumentException If a parameter is invalid + * @throws UnexpectedValueException If a returned value is of an unexpected type or value + */ + public function isEnabled (string $keyPart) { + // Validate parameters + //* NOISY-DEBUG: */ printf('[%s:%d]: keyPart=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $keyPart); + if (empty($keyPart)) { + // Entry is empty + throw new InvalidArgumentException('Parameter "keyPart" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); + } + + // Construct final config key + $configKey = sprintf('is_%s_enabled', $keyPart); + + // Get value from it + //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s' . PHP_EOL, __METHOD__, __LINE__, $configKey); + $isEnabled = $this->getConfigEntry($configKey); + + // Is it Y/N? + //* NOISY-DEBUG: */ printf('[%s:%d]: isEnabled[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($isEnabled)); + if (!is_bool($isEnabled)) { + // Throw exception + throw new UnexpectedValueException(sprintf('isEnabled[]=%s is unexpected', gettype($isEnabled))); + } + + // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: isEnabled=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($isEnabled)); + return $isEnabled; + } + /** * Generates a code for hashes from this class * diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 41648caa..63f0ae60 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -696,7 +696,7 @@ Loaded includes: } } else { // Are debug times enabled? - if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings') == 'Y') { + if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings')) { // Prepent it $message = $this->getPrintableExecutionTime() . $message; } diff --git a/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php b/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php index 964c1b73..a4ef4ffc 100644 --- a/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php +++ b/framework/main/classes/database/backend/lfdb_legacy/class_CachedLocalFileDatabase.php @@ -330,7 +330,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac // Then create the info file //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Creating info table for tableName=%s ...', $tableName)); $this->createTableInfoFile($dataSetInstance); - } elseif ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo[$tableName]['primary'])) { + } elseif (FrameworkBootstrap::getConfigurationInstance()->isEnabled('db_update_primary_forced') && $dataSetInstance->getPrimaryKey() != $this->tableInfo[$tableName]['primary']) { // Set the array element //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Setting primaryKey=%s for tableName=%s ...', $dataSetInstance->getPrimaryKey(), $tableName)); $this->tableInfo[$tableName]['primary'] = $dataSetInstance->getPrimaryKey(); diff --git a/framework/main/classes/feature/class_FrameworkFeature.php b/framework/main/classes/feature/class_FrameworkFeature.php index 1bcec3f8..db57e5cc 100644 --- a/framework/main/classes/feature/class_FrameworkFeature.php +++ b/framework/main/classes/feature/class_FrameworkFeature.php @@ -9,6 +9,9 @@ use Org\Mxchange\CoreFramework\Loader\NoClassException; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils; +// Import SPL stuff +use \InvalidArgumentException; + /** * The general feature management class. No instance is needed as this class * has only public methods that are static. @@ -73,8 +76,16 @@ class FrameworkFeature extends BaseFrameworkSystem { * * @param $featureName Name of the feature to be checked * @return $isEnabled Whether the given feature is enabled + * @throws InvalidArgumentException If a parameter is invalid */ public static function isFeatureEnabled (string $featureName) { + // Check parameter + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FRAMEWORK-FEATURE: featureName=%s - CALLED!', $featureName)); + if (empty($featureName)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "featureName" is empty'); + } + // Is the cache set? if (!isset(self::$enabledFeatures[$featureName]['is_enabled'])) { // Generate config key @@ -85,6 +96,7 @@ class FrameworkFeature extends BaseFrameworkSystem { } // Return "cached" status + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FRAMEWORK-FEATURE: is_enabled[%s]=%d - EXIT!', $featureName, intval(self::$enabledFeatures[$featureName]['is_enabled']))); return self::$enabledFeatures[$featureName]['is_enabled']; } @@ -97,10 +109,17 @@ class FrameworkFeature extends BaseFrameworkSystem { * * @param $featureName Name of the feature to be checked on availability * @return $isAvailable Whether the given feature is available + * @throws InvalidArgumentException If a parameter is invalid */ public static function isFeatureAvailable (string $featureName) { - // Is the cache set? + // Check parameter //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FRAMEWORK-FEATURE: featureName=%s - CALLED!', $featureName)); + if (empty($featureName)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "featureName" is empty'); + } + + // Is the cache set? if (!isset(self::$enabledFeatures[$featureName]['is_available'])) { // Default is not available self::$enabledFeatures[$featureName]['is_available'] = false; diff --git a/framework/main/classes/filter/validator/class_EmailValidatorFilter.php b/framework/main/classes/filter/validator/class_EmailValidatorFilter.php index da354037..b9202e8e 100644 --- a/framework/main/classes/filter/validator/class_EmailValidatorFilter.php +++ b/framework/main/classes/filter/validator/class_EmailValidatorFilter.php @@ -73,7 +73,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable { $email = $requestInstance->getRequestElement('email'); // Is the Email set? - if ((is_null($email)) || (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('register_email_unique') == 'Y')) { + if ((is_null($email)) || (FrameworkBootstrap::getConfigurationInstance()->isEnabled('register_email_unique'))) { // Try it again $email1 = $requestInstance->getRequestElement('email1'); $email2 = $requestInstance->getRequestElement('email2'); diff --git a/framework/main/classes/filter/verifier/class_GraphicalCodeCaptchaVerifierFilter.php b/framework/main/classes/filter/verifier/class_GraphicalCodeCaptchaVerifierFilter.php index 89f0a2d5..5e92facf 100644 --- a/framework/main/classes/filter/verifier/class_GraphicalCodeCaptchaVerifierFilter.php +++ b/framework/main/classes/filter/verifier/class_GraphicalCodeCaptchaVerifierFilter.php @@ -79,12 +79,10 @@ class GraphicalCodeCaptchaVerifierFilter extends BaseFilter implements Filterabl } // Create config entry - $configKey = sprintf('%s_captcha_secured', - $requestInstance->getRequestElement('form') - ); + $configKey = sprintf('%s_captcha_secured', $requestInstance->getRequestElement('form')); // Is the CAPTCHA enabled? - if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configKey) != 'Y') { + if (FrameworkBootstrap::getConfigurationInstance()->isEnabled($configKey)) { // Not enabled, so don't check return; } diff --git a/framework/main/classes/helper/html/blocks/class_HtmlBlockHelper.php b/framework/main/classes/helper/html/blocks/class_HtmlBlockHelper.php index fd717dcc..1ecb8403 100644 --- a/framework/main/classes/helper/html/blocks/class_HtmlBlockHelper.php +++ b/framework/main/classes/helper/html/blocks/class_HtmlBlockHelper.php @@ -91,7 +91,7 @@ class HtmlBlockHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $withRegistration Whether with registration date */ public function ifIncludeRegistrationStamp () { - $withRegistration = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('block_shows_registration') == 'Y'); + $withRegistration = FrameworkBootstrap::getConfigurationInstance()->isEnabled('block_shows_registration'); return $withRegistration; } diff --git a/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php b/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php index 691728bf..dd6fc62f 100644 --- a/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php +++ b/framework/main/classes/helper/html/forms/class_HtmlFormHelper.php @@ -766,7 +766,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $required Whether the email address is required */ public function ifRegisterRequiresEmailVerification () { - $required = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('register_requires_email') == 'Y'); + $required = FrameworkBootstrap::getConfigurationInstance()->isEnabled('register_requires_email'); return $required; } @@ -776,7 +776,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $required Whether profile data shall be asked */ public function ifRegisterIncludesProfile () { - $required = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('register_includes_profile') == 'Y'); + $required = FrameworkBootstrap::getConfigurationInstance()->isEnabled('register_includes_profile'); return $required; } @@ -786,7 +786,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $isSecured Whether this form is secured by a CAPTCHA */ public function ifFormSecuredWithCaptcha () { - $isSecured = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($this->getFormName() . '_captcha_secured') == 'Y'); + $isSecured = FrameworkBootstrap::getConfigurationInstance()->isEnabled($this->getFormName() . '_captcha_secured'); return $isSecured; } @@ -796,7 +796,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $required Whether personal data shall be asked */ public function ifRegisterIncludesPersonaData () { - $required = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('register_personal_data') == 'Y'); + $required = FrameworkBootstrap::getConfigurationInstance()->isEnabled('register_personal_data'); return $required; } @@ -806,7 +806,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $required Whether birthday shall be asked */ public function ifProfileIncludesBirthDay () { - $required = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('profile_includes_birthday') == 'Y'); + $required = FrameworkBootstrap::getConfigurationInstance()->isEnabled('profile_includes_birthday'); return $required; } @@ -816,7 +816,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $isUnique */ public function ifEmailMustBeUnique () { - $isUnique = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('register_email_unique') == 'Y'); + $isUnique = FrameworkBootstrap::getConfigurationInstance()->isEnabled('register_email_unique'); return $isUnique; } @@ -826,7 +826,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $required Whether the specified chat protocol is enabled */ public function ifChatEnabled (string $chatProtocol) { - $required = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('chat_enabled_' . $chatProtocol) == 'Y'); + $required = FrameworkBootstrap::getConfigurationInstance()->isEnabled('chat_protocol_' . $chatProtocol); return $required; } @@ -836,7 +836,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $isEnabled Whether the login is enabled or disabled */ public function ifLoginIsEnabled () { - $isEnabled = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_enabled') == 'Y'); + $isEnabled = FrameworkBootstrap::getConfigurationInstance()->isEnabled('user_login'); return $isEnabled; } @@ -846,7 +846,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $isEnabled Whether the login shall be done by username */ public function ifLoginWithUsername () { - $isEnabled = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_type') == "username"); + $isEnabled = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_type') == 'username'); return $isEnabled; } @@ -856,7 +856,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $isEnabled Whether the login shall be done by email */ public function ifLoginWithEmail () { - $isEnabled = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_type') == "email"); + $isEnabled = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_type') == 'email'); return $isEnabled; } @@ -866,7 +866,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $isAllowed Whether guest login is allowed */ public function ifGuestLoginAllowed () { - $isAllowed = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('guest_login_allowed') == 'Y'); + $isAllowed = FrameworkBootstrap::getConfigurationInstance()->isEnabled('guest_login'); return $isAllowed; } @@ -876,7 +876,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $requireConfirm Whether email change must be confirmed */ public function ifEmailChangeRequireConfirmation () { - $requireConfirm = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('email_change_confirmation') == 'Y'); + $requireConfirm = FrameworkBootstrap::getConfigurationInstance()->isEnabled('email_change_confirmation'); return $requireConfirm; } @@ -896,7 +896,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $emailChange Whether changing email address is allowed */ public function ifEmailChangeAllowed () { - $emailChange = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('email_change_allowed') == 'Y'); + $emailChange = FrameworkBootstrap::getConfigurationInstance()->isEnabled('email_change'); return $emailChange; } @@ -937,7 +937,7 @@ class HtmlFormHelper extends BaseHtmlHelper implements HelpableTemplate { * @return $refillActive Whether the refill page is active */ public function ifRefillPageActive () { - $refillActive = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('refill_page_active') == 'Y'); + $refillActive = FrameworkBootstrap::getConfigurationInstance()->isEnabled('refill_page_active'); return $refillActive; } diff --git a/framework/main/classes/output/debug/console/class_DebugConsoleOutput.php b/framework/main/classes/output/debug/console/class_DebugConsoleOutput.php index 5602c6ed..1e7646d8 100644 --- a/framework/main/classes/output/debug/console/class_DebugConsoleOutput.php +++ b/framework/main/classes/output/debug/console/class_DebugConsoleOutput.php @@ -36,7 +36,7 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre /** * Cached configuration entry 'debug_*_output_timings' */ - private $debugOutputTimings = 'N'; + private $isDebugOutputTimingsEnabled = FALSE; /** * Protected constructor @@ -48,7 +48,7 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre parent::__construct(__CLASS__); // Cache configuration entry - $this->debugOutputTimings = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings'); + $this->isDebugOutputTimingsEnabled = FrameworkBootstrap::getConfigurationInstance()->isEnabled('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_output_timings'); } /** @@ -79,7 +79,7 @@ class DebugConsoleOutput extends BaseDebugOutput implements Debugger, OutputStre } // Are debug times enabled? - if ($this->debugOutputTimings == 'Y') { + if ($this->isDebugOutputTimingsEnabled) { // Output it first $output = $this->getPrintableExecutionTime() . $output; } diff --git a/framework/main/classes/rng/class_RandomNumberGenerator.php b/framework/main/classes/rng/class_RandomNumberGenerator.php index 91c40bb6..a8270adf 100644 --- a/framework/main/classes/rng/class_RandomNumberGenerator.php +++ b/framework/main/classes/rng/class_RandomNumberGenerator.php @@ -119,7 +119,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { $serverIp = 'cluster'; // Do we have a single server? - if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('is_single_server') == 'Y') { + if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('single_server')) { // Then use that IP for extra security $serverIp = FrameworkBootstrap::detectServerAddress(); } @@ -214,7 +214,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem { $key = md5($this->getExtraSalt()); // Get key - if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('crypt_fixed_salt') == 'Y') { + if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('crypt_fixed_salt')) { $key = md5($this->getFixedSalt()); } diff --git a/framework/main/classes/tools/console/class_ConsoleTools.php b/framework/main/classes/tools/console/class_ConsoleTools.php index b46f50b8..a390e2ff 100644 --- a/framework/main/classes/tools/console/class_ConsoleTools.php +++ b/framework/main/classes/tools/console/class_ConsoleTools.php @@ -377,7 +377,7 @@ class ConsoleTools extends BaseFrameworkSystem { // Do we use proxy? if ($helperInstance->isProxyUsed() === true) { // CONNECT method? - if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('proxy_connect_method') == 'Y') { + if (FrameworkBootstrap::getConfigurationInstance()->isEnabled('proxy_connect_method')) { // Setup proxy tunnel $response = $helperInstance->setupProxyTunnel('shipsimu.org', 80, $socketResource); diff --git a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php index d2b92e22..73b93335 100644 --- a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php +++ b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php @@ -64,18 +64,21 @@ class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements * @param $requestInstance An instance of a class with an Requestable interface * @param $responseInstance An instance of a class with an Responseable interface * @return void - * @todo 0% done */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Init counter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TESTS-CONFIGURATION-LOADABLE-CLASSES-FILTER: requestInstance=%s,responseInstance=%s - CALLED!', $requestInstance->__toString(), $responseInstance->__toString())); $passed = 0; $failed = 0; + $skipped = 0; // Loop through all configuration keys foreach (FrameworkBootstrap::getConfigurationInstance()->getConfigurationArray() as $configKey => $configValue) { // Key must end with _class + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TESTS-CONFIGURATION-LOADABLE-CLASSES-FILTER: configKey[%s]=%s,configValue[%s]=%s', gettype($configKey), $configKey, gettype($configValue), $configValue)); if (substr($configKey, -6, 6) != '_class') { // Skip this + $skipped++; continue; } @@ -87,14 +90,14 @@ class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements // Is the config entry valid and class is there? if (!is_string($configValue)) { // Is not a string - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('configValue=%s has unexpected type "%s". FAILED', $configValue, gettype($configValue))); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('configValue=%s has unexpected type "%s", required: string - FAILED!', $configValue, gettype($configValue))); // Skip further tests $failed++; continue; } elseif (!class_exists($configValue)) { // Class not found - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Class "%s" not found. FAILED', $configValue)); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Class "%s" not found. FAILED!', $configValue)); // Skip further tests $failed++; @@ -115,7 +118,7 @@ class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements } // Output result - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Test result: %d okay, %d failed (%0.02f%% passed)', $passed, $failed, ($passed / ($passed + $failed) * 100))); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Test result: %d okay, %d failed (%0.02f%% passed), %d skipped - EXIT!', $passed, $failed, ($passed / ($passed + $failed) * 100), $skipped)); } } -- 2.39.5