From: Roland Häder Date: Fri, 13 Mar 2009 22:43:42 +0000 (+0000) Subject: Variable cfg refactured X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=efcf0ff41ed87f064714652c13fa2f0195d9a133 Variable cfg refactured --- diff --git a/inc/database.php b/inc/database.php index 6a57e201..1a53d0a4 100644 --- a/inc/database.php +++ b/inc/database.php @@ -25,11 +25,8 @@ // Initialize database layer $databaseInstance = null; -// Get config instance -$cfg = FrameworkConfiguration::getInstance(); - // Generate FQFN for the database layer -$fqfn = $cfg->readConfig('base_path') . 'inc/database/lib-' . $cfg->readConfig('db_type') . '.php'; +$fqfn = FrameworkConfiguration::getInstance()->readConfig('base_path') . 'inc/database/lib-' . FrameworkConfiguration::getInstance()->readConfig('db_type') . '.php'; // Load the database layer include if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) { @@ -38,12 +35,12 @@ if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) { } else { // Layer is missing! ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer is missing! (%s) -> R.I.P.", - $cfg->readConfig('db_type') + FrameworkConfiguration::getInstance()->readConfig('db_type') )); } // Clean it up -unset($fqfn, $cfg); +unset($fqfn); // Prepare database instance $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getInstance(), $databaseInstance); diff --git a/inc/includes.php b/inc/includes.php index 20128dbb..f94a2c9b 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -22,11 +22,8 @@ * along with this program. If not, see . */ -// Get config instance -$cfg = FrameworkConfiguration::getInstance(); - // Include the class loader function -require($cfg->readConfig('base_path') . 'inc/loader/class_ClassLoader.php'); +require(FrameworkConfiguration::getInstance()->readConfig('base_path') . 'inc/loader/class_ClassLoader.php'); // Shall we include additional configs where you can configure some things? Then // Load matching config @@ -45,11 +42,11 @@ if (!empty($_GET['app'])) { $application = trim($app[1]); } else { // Invalid entry found, first must be "app"! - $application = $cfg->readConfig('default_application'); + $application = FrameworkConfiguration::getInstance()->readConfig('default_application'); } } else { // Set the "application selector" application - $application = $cfg->readConfig('default_application'); + $application = FrameworkConfiguration::getInstance()->readConfig('default_application'); } // Secure it, by keeping out tags @@ -59,7 +56,7 @@ $application = htmlentities(strip_tags($application), ENT_QUOTES); $application = preg_replace('/([^a-z0-9_-])+/i', '', $application); // Set the application name for later usage -$cfg->setConfigEntry('app_name', $application); +FrameworkConfiguration::getInstance()->setConfigEntry('app_name', $application); // Register auto-load function with the SPL spl_autoload_register('ClassLoader::autoLoad'); @@ -67,7 +64,7 @@ spl_autoload_register('ClassLoader::autoLoad'); /** * Is the devel package included? */ -if (is_dir($cfg->readConfig('base_path') . "devel")) { +if (is_dir(FrameworkConfiguration::getInstance()->readConfig('base_path') . "devel")) { /** * Load all development includes */ diff --git a/inc/selector.php b/inc/selector.php index 7e7dee50..a95bd566 100644 --- a/inc/selector.php +++ b/inc/selector.php @@ -22,12 +22,9 @@ * along with this program. If not, see . */ -// Get config instance -$cfg = FrameworkConfiguration::getInstance(); - // Try to load these includes in the given order $configAppIncludes = array( - 'class_' . $cfg->readConfig('app_helper_class'), // The ApplicationHelper class + 'class_' . FrameworkConfiguration::getInstance()->readConfig('app_helper_class'), // The ApplicationHelper class 'config', // The application's own configuration 'data', // Application data 'init', // The application initializer @@ -46,13 +43,13 @@ foreach ($configAppIncludes as $inc) { } // Generate a FQFN for the helper class - $fqfn = $cfg->readConfig('application_path') . $cfg->readConfig('app_name') . '/' . $inc . '.php'; + $fqfn = FrameworkConfiguration::getInstance()->readConfig('application_path') . FrameworkConfiguration::getInstance()->readConfig('app_name') . '/' . $inc . '.php'; // Does the include file exists? if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) { // Load it require_once($fqfn); - } elseif ($cfg->readConfig('verbose_level') > 0) { + } elseif (FrameworkConfiguration::getInstance()->readConfig('verbose_level') > 0) { // File is missing trigger_error(sprintf("Cannot load application script %s.php! File is missing or read-protected.", $inc @@ -61,7 +58,7 @@ foreach ($configAppIncludes as $inc) { } // Remove variables from namespace, which we don't need -unset($cfg, $inc, $configAppIncludes, $fqfn); +unset($inc, $configAppIncludes, $fqfn); // [EOF] ?> diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 1014d10a..bdf7d4b0 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -58,11 +58,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { // Now try the test $testPassed = false; try { - // Get a configuration instance - $cfg = FrameworkConfiguration::getInstance(); - // Now find a configuration variable that does not exist - $dummy = $cfg->readConfig('does_not_exist'); + $dummy = FrameworkConfiguration::getInstance()->readConfig('does_not_exist'); } catch (ConfigEntryNotFoundException $expected) { // This exception was expected, so it is fine $testPassed = true; @@ -87,11 +84,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { // Now try the test $testPassed = false; try { - // Get a configuration instance - $cfg = FrameworkConfiguration::getInstance(); - // Try to read an empty configuration variable - $dummy = $cfg->readConfig(''); + $dummy = FrameworkConfiguration::getInstance()->readConfig(''); } catch (ConfigEntryIsEmptyException $expected) { // This exception was expected, so it is fine $testPassed = true; @@ -116,11 +110,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase { // Now try the test $testPassed = false; try { - // Get a configuration instance - $cfg = FrameworkConfiguration::getInstance(); - // Try to read an empty configuration variable - $cfg->setConfigEntry('', 'will_never_be_set'); + FrameworkConfiguration::getInstance()->setConfigEntry('', 'will_never_be_set'); } catch (ConfigEntryIsEmptyException $expected) { // This exception was expected, so it is fine $testPassed = true; @@ -144,14 +135,11 @@ class ConfigTest extends PHPUnit_Framework_TestCase { // Try it here $value = "This is a test value"; try { - // Get a configuration instance - $cfg = FrameworkConfiguration::getInstance(); - // Try to read an empty configuration variable - $cfg->setConfigEntry('test_key', "{$value}"); + FrameworkConfiguration::getInstance()->setConfigEntry('test_key', "{$value}"); // Read the config entry we have just written - $readValue = $cfg->readConfig('test_key'); + $readValue = FrameworkConfiguration::getInstance()->readConfig('test_key'); // Now test the values $this->assertEquals($value, $readValue);