From: Roland Häder Date: Sun, 13 Aug 2017 18:36:12 +0000 (+0200) Subject: Rewrite: X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=24814f48bc7bad92f55e8763bf3f657fb41b131d Rewrite: - the configuration instance is now instanciated by FrameworkBootstrap::getConfigurationInstance(), this *may* has made it sure that the class FrameworkConfiguration can be fully covered by unit tests. - still a call-back instance test is pending Signed-off-by: Roland Häder --- diff --git a/application/tests/class_ApplicationHelper.php b/application/tests/class_ApplicationHelper.php index 6b234b43..cc0f5749 100644 --- a/application/tests/class_ApplicationHelper.php +++ b/application/tests/class_ApplicationHelper.php @@ -4,7 +4,6 @@ namespace CoreFramework\Helper\Application; // Import framework stuff use CoreFramework\Bootstrap\FrameworkBootstrap; -use CoreFramework\Configuration\FrameworkConfiguration; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Loader\ClassLoader; use CoreFramework\Manager\ManageableApplication; @@ -176,7 +175,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica */ public function initApplication () { // Get config instance - $cfg = FrameworkConfiguration::getSelfInstance(); + $cfg = FrameworkBootstrap::getConfigurationInstance(); // Initialize output system self::createDebugInstance('ApplicationHelper'); diff --git a/application/tests/config.php b/application/tests/config.php index 0574a8db..3a0ee3e9 100644 --- a/application/tests/config.php +++ b/application/tests/config.php @@ -1,6 +1,6 @@ setConfigEntry('default_console_command', 'main'); diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index a37c6bf9..2b79f2c4 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -63,6 +63,11 @@ final class FrameworkBootstrap { */ private static $responseInstance = NULL; + /** + * Instance of a FrameworkConfiguration class + */ + private static $configurationInstance = NULL; + /* * Includes applications may have. They will be tried in the given order, * some will become soon deprecated. @@ -96,6 +101,22 @@ final class FrameworkBootstrap { // Prevent making instances from this "utilities" class } + /** + * Some "getter" for a configuration instance, making sure, it is unique + * + * @return $configurationInstance An instance of a FrameworkConfiguration class + */ + public static function getConfigurationInstance () { + // Is the instance there? + if (is_null(self::$configurationInstance)) { + // Init new instance + self::$configurationInstance = new FrameworkConfiguration(); + } // END - if + + // Return it + return self::$configurationInstance; + } + /** * Getter for request instance * @@ -277,8 +298,8 @@ final class FrameworkBootstrap { */ public static function prepareApplication () { // Configuration entry 'detected_app_name' must be set, get it here, including full path - $application = FrameworkConfiguration::getSelfInstance()->getConfigEntry('detected_app_name'); - $fullPath = FrameworkConfiguration::getSelfInstance()->getConfigEntry('detected_full_app_path'); + $application = self::getConfigurationInstance()->getConfigEntry('detected_app_name'); + $fullPath = self::getConfigurationInstance()->getConfigEntry('detected_full_app_path'); /* * Now check and load all files, found deprecated files will throw a @@ -325,7 +346,7 @@ final class FrameworkBootstrap { */ public static function startApplication () { // Configuration entry 'detected_app_name' must be set, get it here - $application = FrameworkConfiguration::getSelfInstance()->getConfigEntry('detected_app_name'); + $application = self::getConfigurationInstance()->getConfigEntry('detected_app_name'); // Is there an application helper instance? $applicationInstance = call_user_func_array( @@ -383,7 +404,7 @@ final class FrameworkBootstrap { } // END - if // Initialize database layer - $databaseInstance = ObjectFactory::createObjectByConfiguredName(FrameworkConfiguration::getSelfInstance()->getConfigEntry('database_type') . '_class'); + $databaseInstance = ObjectFactory::createObjectByConfiguredName(self::getConfigurationInstance()->getConfigEntry('database_type') . '_class'); // Prepare database instance $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance); @@ -550,7 +571,7 @@ final class FrameworkBootstrap { */ private static function scanFrameworkClasses () { // Include the class loader function - require FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php'; + require self::getConfigurationInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php'; // Register auto-load function with the SPL spl_autoload_register('CoreFramework\Loader\ClassLoader::autoLoad'); @@ -619,7 +640,7 @@ final class FrameworkBootstrap { // Construct FQPN (Full-Qualified Path Name) for ApplicationHelper class $applicationPath = sprintf( '%s%s%s', - FrameworkConfiguration::getSelfInstance()->getConfigEntry('application_base_path'), + self::getConfigurationInstance()->getConfigEntry('application_base_path'), $application, DIRECTORY_SEPARATOR ); @@ -632,8 +653,8 @@ final class FrameworkBootstrap { } // END - if // Set the detected application's name and full path for later usage - FrameworkConfiguration::getSelfInstance()->setConfigEntry('detected_full_app_path', $applicationPath); - FrameworkConfiguration::getSelfInstance()->setConfigEntry('detected_app_name' , $application); + self::getConfigurationInstance()->setConfigEntry('detected_full_app_path', $applicationPath); + self::getConfigurationInstance()->setConfigEntry('detected_app_name' , $application); } /** * Setter for request instance diff --git a/framework/config-global.php b/framework/config-global.php index bf734267..bd162318 100644 --- a/framework/config-global.php +++ b/framework/config-global.php @@ -1,6 +1,5 @@ setConfigEntry('root_base_path', ApplicationEntryPoint::getRootPath() . DIRECTORY_SEPARATOR); diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index 82d50bf9..0826076e 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -48,12 +48,7 @@ class FrameworkConfiguration implements Registerable { * hard-coded configuration data and might be overwritten/extended by * config data from the database. */ - private $config = array(); - - /** - * The configuration instance itself - */ - private static $configInstance = NULL; + private static $config = array(); /** * Call-back instance (unused) @@ -66,11 +61,12 @@ class FrameworkConfiguration implements Registerable { const EXCEPTION_CONFIG_VALUE_TYPE_UNSUPPORTED = 0x132; /** - * Private constructor + * Default constructor, the configuration entries are static, not the + * whole instance. * * @return void */ - private function __construct () { + public function __construct () { // Empty for now } @@ -83,22 +79,6 @@ class FrameworkConfiguration implements Registerable { return get_class($this); } - /** - * Getter for a singleton instance of this class - * - * @return $configInstance A singleton instance of this class - */ - public static final function getSelfInstance () { - // is the instance there? - if (is_null(self::$configInstance)) { - // Create a config instance - self::$configInstance = new FrameworkConfiguration(); - } // END - if - - // Return singleton instance - return self::$configInstance; - } - /** * Checks whether the given configuration key is set * @@ -121,7 +101,7 @@ class FrameworkConfiguration implements Registerable { } // Is it set? - $isset = ((isset($this->config[$configKey])) || (array_key_exists($configKey, $this->config))); + $isset = ((isset(self::$config[$configKey])) || (array_key_exists($configKey, self::$config))); // Return the result return $isset; @@ -159,7 +139,7 @@ class FrameworkConfiguration implements Registerable { } // END - if // Return the requested value - return $this->config[$configKey]; + return self::$config[$configKey]; } /** @@ -193,10 +173,10 @@ class FrameworkConfiguration implements Registerable { // Set the configuration value //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configKey . ',configValue[' . gettype($configValue) . ']=' . $configValue . PHP_EOL); - $this->config[$configKey] = $configValue; + self::$config[$configKey] = $configValue; // Resort the array - ksort($this->config); + ksort(self::$config); } /** @@ -206,7 +186,7 @@ class FrameworkConfiguration implements Registerable { */ public final function getConfigurationArray () { // Return it - return $this->config; + return self::$config; } /** @@ -242,7 +222,7 @@ class FrameworkConfiguration implements Registerable { } // END - if // Unset it - unset($this->config[$configKey]); + unset(self::$config[$configKey]); } /** diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 63f6d00d..5ae12d77 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -220,7 +220,7 @@ class ClassLoader { $loaderInstance = self::getSelfInstance(); // Get config instance - $configInstance = FrameworkConfiguration::getSelfInstance(); + $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Load all classes foreach (self::$frameworkPaths as $shortPath) { @@ -269,7 +269,7 @@ class ClassLoader { $loaderInstance = self::getSelfInstance(); // Get config instance - $configInstance = FrameworkConfiguration::getSelfInstance(); + $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Load all classes for the application foreach (self::$frameworkPaths as $shortPath) { @@ -310,7 +310,7 @@ class ClassLoader { //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); // Get config instance - $configInstance = FrameworkConfiguration::getSelfInstance(); + $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Load all classes for the application foreach (self::$testPaths as $shortPath) { @@ -399,7 +399,7 @@ class ClassLoader { // Is the instance there? if (is_null(self::$selfInstance)) { // Get a new one - self::$selfInstance = ClassLoader::createClassLoader(FrameworkConfiguration::getSelfInstance()); + self::$selfInstance = ClassLoader::createClassLoader(FrameworkBootstrap::getConfigurationInstance()); } // END - if // Return the instance diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 2d9aa984..f88b8d36 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -466,7 +466,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Set configuration instance if no registry ... if (!$this instanceof Register) { // ... because registries doesn't need to be configured - $this->setConfigInstance(FrameworkConfiguration::getSelfInstance()); + $this->setConfigInstance(FrameworkBootstrap::getConfigurationInstance()); } // END - if // Is the startup time set? (0 cannot be true anymore) @@ -1853,7 +1853,7 @@ Loaded includes: // Try it try { // Get a debugger instance - $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className); + $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className); } catch (NullPointerException $e) { // Didn't work, no instance there exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber)); @@ -3299,7 +3299,7 @@ Loaded includes: */ protected static function createTempPathForFile (SplFileInfo $infoInstance) { // Get config entry - $basePath = FrameworkConfiguration::getSelfInstance()->getConfigEntry('temp_file_path'); + $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path'); // Is the path writeable? if (!is_writable($basePath)) { diff --git a/framework/main/classes/factories/objects/class_ObjectFactory.php b/framework/main/classes/factories/objects/class_ObjectFactory.php index ebde6249..2701ede9 100644 --- a/framework/main/classes/factories/objects/class_ObjectFactory.php +++ b/framework/main/classes/factories/objects/class_ObjectFactory.php @@ -3,7 +3,7 @@ namespace CoreFramework\Factory; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Generic\EmptyVariableException; use CoreFramework\Loader\NoClassException; @@ -97,7 +97,7 @@ class ObjectFactory extends BaseFactory { */ public static final function createObjectByConfiguredName ($configEntry, array $args = array()) { // Read the configuration entry - $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($configEntry); + $className = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry); // Send this to the other factory... $objectInstance = self::createObjectByName($className, $args); diff --git a/framework/main/classes/factories/stacks/class_FileStackFactory.php b/framework/main/classes/factories/stacks/class_FileStackFactory.php index 957810fb..6ce4332d 100644 --- a/framework/main/classes/factories/stacks/class_FileStackFactory.php +++ b/framework/main/classes/factories/stacks/class_FileStackFactory.php @@ -3,7 +3,7 @@ namespace CoreFramework\Factory\Stack; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Registry\Registry; @@ -50,10 +50,10 @@ class FileStackFactory extends ObjectFactory { public static final function createFileStackInstance ($prefix, $stackName) { // Construct file stack name $stackFileName = sprintf('%s%s/%s.%s', - FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path'), - FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_file_stacks_path'), + FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('framework_base_path'), + FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_file_stacks_path'), $stackName, - FrameworkConfiguration::getSelfInstance()->getConfigEntry('file_stacks_extension') + FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('file_stacks_extension') ); // If there is no handler? diff --git a/framework/main/classes/factories/user/class_UserFactory.php b/framework/main/classes/factories/user/class_UserFactory.php index 3e15d028..80602114 100644 --- a/framework/main/classes/factories/user/class_UserFactory.php +++ b/framework/main/classes/factories/user/class_UserFactory.php @@ -3,7 +3,7 @@ namespace CoreFramework\Factory\User; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Registry\Registry; use CoreFramework\Request\Requestable; @@ -59,13 +59,13 @@ class UserFactory extends ObjectFactory { // Probe on member instance try { // Get class name - $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry('user_class'); + $className = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_class'); // Try to instance it $userInstance = call_user_func_array(array($className, 'createMemberByRequest'), array($requestInstance)); } catch (UnexpectedGuestAccountException $e) { // Then try it with guest account - $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry('guest_class'); + $className = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('guest_class'); // Try to instance it $userInstance = call_user_func_array(array($className, 'createGuestByRequest'), array($requestInstance)); diff --git a/framework/main/classes/feature/class_FrameworkFeature.php b/framework/main/classes/feature/class_FrameworkFeature.php index 09fa8263..6f0c55c9 100644 --- a/framework/main/classes/feature/class_FrameworkFeature.php +++ b/framework/main/classes/feature/class_FrameworkFeature.php @@ -3,7 +3,7 @@ namespace CoreFramework\Feature; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Loader\NoClassException; use CoreFramework\Object\BaseFrameworkSystem; @@ -80,7 +80,7 @@ class FrameworkFeature extends BaseFrameworkSystem { $configKey = sprintf('enable_feature_%s', $featureName); // Check configuration - self::$enabledFeatures[$featureName]['is_enabled'] = (FrameworkConfiguration::getSelfInstance()->getConfigEntry($configKey) === 'Y'); + self::$enabledFeatures[$featureName]['is_enabled'] = (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configKey) === 'Y'); } // END - if // Return "cached" status diff --git a/framework/main/classes/language/class_LanguageSystem.php b/framework/main/classes/language/class_LanguageSystem.php index 6e775009..657c1137 100644 --- a/framework/main/classes/language/class_LanguageSystem.php +++ b/framework/main/classes/language/class_LanguageSystem.php @@ -3,7 +3,7 @@ namespace CoreFramework\Localization; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Object\BaseFrameworkSystem; use CoreFramework\Registry\Registerable; use CoreFramework\Registry\Registry; @@ -113,7 +113,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, $langInstance->initLanguageStrings(); // Set language code from default config - $langInstance->setLanguageCode(FrameworkConfiguration::getSelfInstance()->getConfigEntry('default_lang')); + $langInstance->setLanguageCode(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_lang')); // Remember this instance self::$selfInstance = $langInstance; diff --git a/framework/main/classes/output/console/class_ConsoleOutput.php b/framework/main/classes/output/console/class_ConsoleOutput.php index 52e6bc7f..f7dbd4bf 100644 --- a/framework/main/classes/output/console/class_ConsoleOutput.php +++ b/framework/main/classes/output/console/class_ConsoleOutput.php @@ -3,7 +3,7 @@ namespace CoreFramework\Output; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Generic\UnsupportedOperationException; use CoreFramework\Output\BaseOutput; use CoreFramework\Stream\Output\OutputStreamer; @@ -81,7 +81,7 @@ class ConsoleOutput extends BaseOutput implements OutputStreamer { public static final function getInstance() { // Is the self-instance already set? if (is_null(self::$consoleInstance)) { - $contentType = FrameworkConfiguration::getSelfInstance()->getConfigEntry('web_content_type'); + $contentType = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('web_content_type'); self::$consoleInstance = ConsoleOutput::createConsoleOutput($contentType); } // END - if diff --git a/framework/main/classes/tools/console/class_ConsoleTools.php b/framework/main/classes/tools/console/class_ConsoleTools.php index d730677c..a5d50ba2 100644 --- a/framework/main/classes/tools/console/class_ConsoleTools.php +++ b/framework/main/classes/tools/console/class_ConsoleTools.php @@ -3,7 +3,7 @@ namespace CoreFramework\Console\Tools; // Import framework stuff -use CoreFramework\Configuration\FrameworkConfiguration; +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Filesystem\FileNotFoundException; use CoreFramework\Generic\FrameworkException; @@ -55,7 +55,7 @@ class ConsoleTools extends BaseFrameworkSystem { parent::__construct(__CLASS__); // Cache configuration entry - self::$quietResolver = FrameworkConfiguration::getSelfInstance()->getConfigEntry('quiet_dns_resolver'); + self::$quietResolver = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('quiet_dns_resolver'); } /** diff --git a/index.php b/index.php index c5ab7dd8..6ac80114 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,6 @@ namespace CoreFramework\EntryPoint; // Import framework stuff use CoreFramework\Bootstrap\FrameworkBootstrap; -use CoreFramework\Configuration\FrameworkConfiguration; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Filesystem\FileNotFoundException; use CoreFramework\Helper\Application\ApplicationHelper; @@ -75,7 +74,7 @@ final class ApplicationEntryPoint { } // END - if // Get config instance - $configInstance = FrameworkConfiguration::getSelfInstance(); + $configInstance = FrameworkBootstrap::getConfigurationInstance(); // Do we have debug installation? if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index de3ab8ee..7b102e0f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,7 +1,6 @@ @@ -45,4 +44,4 @@ if (extension_loaded('xdebug')) { require dirname(__DIR__) . '/vendor/autoload.php'; // Quiet DNS resolver as this is not wanted here -FrameworkConfiguration::getSelfInstance()->setConfigEntry('quiet_dns_resolver', TRUE); +FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('quiet_dns_resolver', TRUE); diff --git a/tests/framework/config/FrameworkConfigurationTest.php b/tests/framework/config/FrameworkConfigurationTest.php index 4de7bbcc..42040b70 100644 --- a/tests/framework/config/FrameworkConfigurationTest.php +++ b/tests/framework/config/FrameworkConfigurationTest.php @@ -1,9 +1,10 @@ assertEquals(self::$configInstance, $dummyInstance); @@ -103,7 +104,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testEqualsConfigInstance () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = new FrameworkConfiguration(); // Should return TRUE $this->assertTrue(self::$configInstance->equals($dummyInstance)); @@ -114,7 +115,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testHashCodeConfigInstance () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = FrameworkBootstrap::getConfigurationInstance(); // Get hash code from both $hashCodeExpected = self::$configInstance->hashCode(); @@ -152,7 +153,7 @@ class FrameworkConfigurationTest extends TestCase { */ public function testSameConfigurationArrayGetter () { // Get instance - $dummyInstance = FrameworkConfiguration::getSelfInstance(); + $dummyInstance = FrameworkBootstrap::getConfigurationInstance(); // Get it from both instances $config1 = self::$configInstance->getConfigurationArray();