Variable cfg refactured
authorRoland Häder <roland@mxchange.org>
Fri, 13 Mar 2009 22:43:42 +0000 (22:43 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 13 Mar 2009 22:43:42 +0000 (22:43 +0000)
inc/database.php
inc/includes.php
inc/selector.php
tests/ConfigTest.php

index 6a57e201c5442bc4f1409bcfccb25c41d0672470..1a53d0a4a2f0b4eb35e3d151870007fd463e78a1 100644 (file)
 // Initialize database layer
 $databaseInstance = null;
 
 // Initialize database layer
 $databaseInstance = null;
 
-// Get config instance
-$cfg = FrameworkConfiguration::getInstance();
-
 // Generate FQFN for the database layer
 // 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))) {
 
 // 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) -&gt; R.I.P.",
 } else {
        // Layer is missing!
        ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer is missing! (%s) -&gt; R.I.P.",
-               $cfg->readConfig('db_type')
+               FrameworkConfiguration::getInstance()->readConfig('db_type')
        ));
 }
 
 // Clean it up
        ));
 }
 
 // Clean it up
-unset($fqfn, $cfg);
+unset($fqfn);
 
 // Prepare database instance
 $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getInstance(), $databaseInstance);
 
 // Prepare database instance
 $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getInstance(), $databaseInstance);
index 20128dbb0776595cae72ce0fbada5d5bde649aee..f94a2c9beed3a1eb76e6f0c8fcb00adbdfc4c2f3 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-// Get config instance
-$cfg = FrameworkConfiguration::getInstance();
-
 // Include the class loader function
 // 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
 
 // 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 = 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
        }
 } else {
        // Set the "application selector" application
-       $application = $cfg->readConfig('default_application');
+       $application = FrameworkConfiguration::getInstance()->readConfig('default_application');
 }
 
 // Secure it, by keeping out tags
 }
 
 // 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
 $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');
 
 // 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?
  */
 /**
  * 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
         */
        /**
         * Load all development includes
         */
index 7e7dee502a316feb47ebdecce3af46a4feb6e6b5..a95bd566fc6af67420cebc90a9748b4c59b451f6 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-// Get config instance
-$cfg = FrameworkConfiguration::getInstance();
-
 // Try to load these includes in the given order
 $configAppIncludes = array(
 // 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
        '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
        }
 
        // 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);
 
        // 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
                // 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
 }
 
 // Remove variables from namespace, which we don't need
-unset($cfg, $inc, $configAppIncludes, $fqfn);
+unset($inc, $configAppIncludes, $fqfn);
 
 // [EOF]
 ?>
 
 // [EOF]
 ?>
index 1014d10adb143571f68e1c6728826307aefb6123..bdf7d4b0a4ee88679fd8ef96c7ef65f955d993cc 100644 (file)
@@ -58,11 +58,8 @@ class ConfigTest extends PHPUnit_Framework_TestCase {
                // Now try the test
                $testPassed = false;
                try {
                // Now try the test
                $testPassed = false;
                try {
-                       // Get a configuration instance
-                       $cfg = FrameworkConfiguration::getInstance();
-
                        // Now find a configuration variable that does not exist
                        // 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;
                } 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 {
                // Now try the test
                $testPassed = false;
                try {
-                       // Get a configuration instance
-                       $cfg = FrameworkConfiguration::getInstance();
-
                        // Try to read an empty configuration variable
                        // 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;
                } 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 {
                // Now try the test
                $testPassed = false;
                try {
-                       // Get a configuration instance
-                       $cfg = FrameworkConfiguration::getInstance();
-
                        // Try to read an empty configuration variable
                        // 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;
                } 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 {
                // Try it here
                $value = "This is a test value";
                try {
-                       // Get a configuration instance
-                       $cfg = FrameworkConfiguration::getInstance();
-
                        // Try to read an empty configuration variable
                        // 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
 
                        // 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);
 
                        // Now test the values
                        $this->assertEquals($value, $readValue);