From 6acaeb0b08448f701ca13f50aec3ee89ba6ab948 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 2 Apr 2017 20:44:02 +0200 Subject: [PATCH] Continued: - renamed BootstrapFramework -> FrameworkBootstrap as there are also similar classes around, like FrameworkConfiguration - require/include are no functions, don't use parentheses here (including old tests, I know) - continued with rewriting bootstrap: more methods in FrameworkBootstrap and lesser include files in framework/ path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- application/tests/init.php | 8 ++++-- framework/bootstrap/bootstrap.inc.php | 6 ++-- ...ework.php => class_FrameworkBootstrap.php} | 25 +++++++++++++---- framework/config.inc.php | 6 ++-- framework/database.php | 2 +- framework/includes.php | 2 +- framework/loader/class_ClassLoader.php | 6 ++-- framework/selector.php | 2 +- index.php | 28 ++++++++++++++----- tests/ConfigTest.php | 8 +++--- tests/RegistryTest.php | 8 +++--- tests/RequestTest.php | 8 +++--- tests/Test.php | 8 +++--- tests/old/contract-test.php | 12 ++++---- tests/old/loader-test.php | 12 ++++---- tests/old/personell-test.php | 12 ++++---- 16 files changed, 92 insertions(+), 61 deletions(-) rename framework/bootstrap/{class_BootstrapFramework.php => class_FrameworkBootstrap.php} (60%) diff --git a/application/tests/init.php b/application/tests/init.php index 29dfc167..6266e1c8 100644 --- a/application/tests/init.php +++ b/application/tests/init.php @@ -35,9 +35,11 @@ $cfg = FrameworkConfiguration::getSelfInstance(); // Initialize output system ApplicationHelper::createDebugInstance('ApplicationHelper'); -// This application needs a database connection then we have to simply include -// the framework/database.php script -require($cfg->getConfigEntry('framework_base_path') . 'database.php'); +/* + * This application needs a database connection then we have to simply include + * the framework/database.php script + */ +require $cfg->getConfigEntry('framework_base_path') . 'database.php'; // Register core tests ClassLoader::registerTestsPath('framework/main/tests'); diff --git a/framework/bootstrap/bootstrap.inc.php b/framework/bootstrap/bootstrap.inc.php index 4c2ebd42..848e6898 100644 --- a/framework/bootstrap/bootstrap.inc.php +++ b/framework/bootstrap/bootstrap.inc.php @@ -1,6 +1,6 @@ . */ -final class BootstrapFramework { +final class FrameworkBootstrap { /** * Private constructor, no instance is needed from this class as only * static methods exist. @@ -43,12 +43,27 @@ final class BootstrapFramework { */ public static function doBootstrap () { // Load basic include files to continue bootstrapping - require(ApplicationEntryPoint::detectFrameworkPath() . 'main/interfaces/class_FrameworkInterface.php'); - require(ApplicationEntryPoint::detectFrameworkPath() . 'main/interfaces/registry/class_Registerable.php'); - require(ApplicationEntryPoint::detectFrameworkPath() . 'config/class_FrameworkConfiguration.php'); + require ApplicationEntryPoint::detectFrameworkPath() . 'main/interfaces/class_FrameworkInterface.php'; + require ApplicationEntryPoint::detectFrameworkPath() . 'main/interfaces/registry/class_Registerable.php'; + require ApplicationEntryPoint::detectFrameworkPath() . 'config/class_FrameworkConfiguration.php'; // Load main configuration - require(ApplicationEntryPoint::detectFrameworkPath() . 'config.inc.php'); + require ApplicationEntryPoint::detectFrameworkPath() . 'config.inc.php'; + } + + /** + * Checks all parameters, like $_GET, $_POST, $_COOKIE and also "emulated" + * from command-line. Accepted CLI parameters are in following forms: + * + * --foo=bar - parameter 'foo' gets value "bar" (string) + * --enable-foo=true - parameter 'enableFoo' gets value true (boolean) + * --baz=123 - parameter 'baz' get value 123 (interger) + * + * The same also works without 2 dashes as it was possible before: + * + * app=tests - launches application 'tests' (parameter 'app' gets string value "tests") + */ + public static function checkParameters () { } } diff --git a/framework/config.inc.php b/framework/config.inc.php index 1ea33974..e0498c68 100644 --- a/framework/config.inc.php +++ b/framework/config.inc.php @@ -1,7 +1,7 @@ setConfigEntry('root_base_path', BootstrapFramework::detectRootPath() . '/'); +$cfg->setConfigEntry('root_base_path', ApplicationEntryPoint::getRootPath() . '/'); // CFG: CORE-BASE-PATH $cfg->setConfigEntry('framework_base_path', ApplicationEntryPoint::detectFrameworkPath()); @@ -82,7 +82,7 @@ $cfg->setConfigEntry('language_base_path', 'language/'); $cfg->setConfigEntry('compressor_base_path', 'main/classes/compressor/'); // CFG: APPLICATION-BASE-PATH -$cfg->setConfigEntry('application_base_path', FrameworkBootstrap::detectApplicationBasePath()); +$cfg->setConfigEntry('application_base_path', $cfg->getConfigEntry('root_base_path') . 'application/'); // CFG: COMPILE-OUTPUT-PATH $cfg->setConfigEntry('compile_output_path', 'templates/_compiled/'); diff --git a/framework/database.php b/framework/database.php index 2a13ed54..fe39b3b0 100644 --- a/framework/database.php +++ b/framework/database.php @@ -44,7 +44,7 @@ $fqfn = sprintf( // Load the database layer include if (BaseFrameworkSystem::isReadableFile($fqfn)) { // Load the layer - require($fqfn); + require $fqfn; } else { // Layer is missing! ApplicationEntryPoint::app_exit(sprintf('[Main:] Database layer is missing! (%s) -> R.I.P.', diff --git a/framework/includes.php b/framework/includes.php index 3764ca73..ceaab36d 100644 --- a/framework/includes.php +++ b/framework/includes.php @@ -29,7 +29,7 @@ use CoreFramework\Loader\ClassLoader; */ // Include the class loader function -require(FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php'); +require FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php'; /* * Shall we include additional configs where you can configure some things? diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index bc37b2ad..939d3559 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -519,7 +519,7 @@ class ClassLoader { // Does the class cache exist? if (BaseFrameworkSystem::isReadableFile($this->listCacheFQFN)) { // Then include it - require($this->classCacheFQFN); + require $this->classCacheFQFN; // Mark the class cache as loaded $this->classesCached = TRUE; @@ -559,7 +559,7 @@ class ClassLoader { if ((isset($this->foundClasses[$fileName])) && (!isset($this->loadedClasses[$this->foundClasses[$fileName]]))) { // File is found and not loaded so load it only once //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); - require($this->foundClasses[$fileName]); + require $this->foundClasses[$fileName]; //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); // Count this loaded class/interface/exception @@ -596,7 +596,7 @@ class ClassLoader { if (substr($fileName, 0, strlen($this->prefix)) == $this->prefix) { // Then include it //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - START' . PHP_EOL, __METHOD__, __LINE__, $fileName); - require($fqfn); + require $fqfn; //* NOISY-DEBUG: */ printf('[%s:%d] LOAD: %s - END' . PHP_EOL, __METHOD__, __LINE__, $fileName); // Remove it from the list diff --git a/framework/selector.php b/framework/selector.php index abedae92..7f88c168 100644 --- a/framework/selector.php +++ b/framework/selector.php @@ -65,7 +65,7 @@ foreach ($configAppIncludes as $appInc) { if (BaseFrameworkSystem::isReadableFile($appFqFn)) { // Load it //* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - START\n"; - require($appFqFn); + require $appFqFn; //* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - END\n"; } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('verbose_level') > 0) { // File is missing diff --git a/index.php b/index.php index ecf66b48..c0671792 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ namespace CoreFramework\EntryPoint; // Import framework stuff +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Configuration\FrameworkConfiguration; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Helper\Application\ApplicationHelper; @@ -82,7 +83,7 @@ final class ApplicationEntryPoint { } // END - if // Get some instances - $tpl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('html_template_class'); + $tpl = $configInstance->getConfigEntry('html_template_class'); $languageInstance = LanguageSystem::getSelfInstance(); // Initialize template instance here to avoid warnings in IDE @@ -98,7 +99,7 @@ final class ApplicationEntryPoint { // Get the template instance from our object factory $templateInstance = ObjectFactory::createObjectByName($tpl); } catch (FrameworkException $e) { - exit(sprintf("[Main:] Could not initialize template engine for reason: %s", + exit(sprintf('[Main:] Could not initialize template engine for reason: %s', $e->getMessage() )); } @@ -119,7 +120,7 @@ final class ApplicationEntryPoint { } // END - if // Add the traceback path to the final output - $backtrace .= sprintf("%s:%d, %s(%d)
\n", + $backtrace .= sprintf('%s:%d, %s(%d)
' . PHP_EOL, basename($trace['file']), $trace['line'], $trace['function'], @@ -214,7 +215,7 @@ final class ApplicationEntryPoint { ); // Debug message - /* NOISY-DEBUG: */ printf('[%s:%d]: fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fqfn); + //* NOISY-DEBUG: */ printf('[%s:%d]: fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fqfn); // Is it readable? if (is_readable($fqfn)) { @@ -237,6 +238,16 @@ final class ApplicationEntryPoint { return self::$frameworkPath; } + /** + * Getter for root path + * + * @return $rootPath Root path + */ + public static function getRootPath () { + // Get __DIR__, really simple and no detection + return __DIR__; + } + /** * The framework's main entry point. This class isolates some local * variables which shall not become visible to outside because of security @@ -247,10 +258,13 @@ final class ApplicationEntryPoint { */ public static final function main () { // Load bootstrap file - require(self::detectFrameworkPath() . 'bootstrap/bootstrap.inc.php'); + require self::detectFrameworkPath() . 'bootstrap/bootstrap.inc.php'; - // Get a new configuration instance - $cfg = FrameworkConfiguration::getSelfInstance(); + /* + * Initial bootstrap is done, continue with checking parameters and + * look for 'app'. + */ + FrameworkBootstrap::checkParameters(); } } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 968452a5..127c7a29 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -5,13 +5,13 @@ print (basename(__FILE__).": Init...\n"); @chdir(".."); // Load config file -require(dirname(dirname(__FILE__)) . '/framework/config.php'); +require dirname(dirname(__FILE__)) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); @@ -20,7 +20,7 @@ FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'sh define('TEST_MODE', true); // Load the PHPUnit framework -require('PHPUnit/Framework.php'); +require 'PHPUnit/Framework.php'; print (basename(__FILE__).": Init completed.\n\n"); diff --git a/tests/RegistryTest.php b/tests/RegistryTest.php index 846ec55c..89b18a3f 100644 --- a/tests/RegistryTest.php +++ b/tests/RegistryTest.php @@ -5,13 +5,13 @@ print (basename(__FILE__).": Init...\n"); @chdir(".."); // Load config file -require(dirname(dirname(__FILE__)) . '/framework/config.php'); +require dirname(dirname(__FILE__)) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); @@ -20,7 +20,7 @@ FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'sh define('TEST_MODE', true); // Load the PHPUnit framework -require('PHPUnit/Framework.php'); +require 'PHPUnit/Framework.php'; print (basename(__FILE__).": Init completed.\n\n"); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 80d78e47..81a9da8a 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -5,13 +5,13 @@ print (basename(__FILE__).": Init...\n"); @chdir(".."); // Load config file -require(dirname(dirname(__FILE__)) . '/framework/config.php'); +require dirname(dirname(__FILE__)) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); @@ -20,7 +20,7 @@ FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'sh define('TEST_MODE', true); // Load the PHPUnit framework -require('PHPUnit/Framework.php'); +require 'PHPUnit/Framework.php'; print (basename(__FILE__).": Init completed.\n\n"); diff --git a/tests/Test.php b/tests/Test.php index 2e8e6565..6783f7f7 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -5,13 +5,13 @@ print (basename(__FILE__).": Init...\n"); @chdir(".."); // Load config file -require(dirname(dirname(__FILE__)) . '/framework/config.php'); +require dirname(dirname(__FILE__)) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); @@ -20,7 +20,7 @@ FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'sh define('TEST_MODE', true); // Load the PHPUnit framework -require('PHPUnit/Framework.php'); +require 'PHPUnit/Framework.php'; print (basename(__FILE__).": Init completed.\n\n"); die("You need to remove this line (".__LINE__.") and implement this test!\n"); diff --git a/tests/old/contract-test.php b/tests/old/contract-test.php index b4de26a7..5ddac047 100644 --- a/tests/old/contract-test.php +++ b/tests/old/contract-test.php @@ -6,26 +6,26 @@ define('TEST_MODE', true); // Load config file -require(dirname(dirname(dirname(__FILE__))) . '/framework/config.php'); +require dirname(dirname(dirname(__FILE__))) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Load file I/O handler -require($cfg->getConfigEntry('framework_base_path') . 'file_io.php'); +require $cfg->getConfigEntry('framework_base_path') . 'file_io.php'; // Load database layer -require($cfg->getConfigEntry('framework_base_path') . 'database.php'); +require $cfg->getConfigEntry('framework_base_path') . 'database.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); $application = 'shipsimu'; // Load more includes -require($cfg->getConfigEntry('root_base_path') . 'application/shipsimu/loader.php'); +require $cfg->getConfigEntry('root_base_path') . 'application/shipsimu/loader.php'; // Wir tun hier so, als waere schon das Reederei-Objekt generiert und wir wollen // jetzt die Personalliste wiederherstellen diff --git a/tests/old/loader-test.php b/tests/old/loader-test.php index ef18401a..ae0fc99c 100644 --- a/tests/old/loader-test.php +++ b/tests/old/loader-test.php @@ -6,26 +6,26 @@ define('TEST_MODE', true); // Load config file -require(dirname(dirname(dirname(__FILE__))) . '/framework/config.php'); +require dirname(dirname(dirname(__FILE__))) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Load file I/O handler -require($cfg->getConfigEntry('framework_base_path') . 'file_io.php'); +require $cfg->getConfigEntry('framework_base_path') . 'file_io.php'; // Load database layer -require($cfg->getConfigEntry('framework_base_path') . 'database.php'); +require $cfg->getConfigEntry('framework_base_path') . 'database.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); $application = 'shipsimu'; // Load more includes -require($cfg->getConfigEntry('root_base_path') . 'application/shipsimu/loader.php'); +require $cfg->getConfigEntry('root_base_path') . 'application/shipsimu/loader.php'; // Wir tun hier so, als waere schon das Reederei-Objekt generiert und wir wollen // jetzt die Personalliste wiederherstellen diff --git a/tests/old/personell-test.php b/tests/old/personell-test.php index df2ef254..cd1f48cd 100644 --- a/tests/old/personell-test.php +++ b/tests/old/personell-test.php @@ -6,26 +6,26 @@ define('TEST_MODE', true); // Load config file -require(dirname(dirname(dirname(__FILE__))) . '/framework/config.php'); +require dirname(dirname(dirname(__FILE__))) . '/framework/config.php'; // Load all include files -require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'includes.php'; // Load all game classes -require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); +require $cfg->getConfigEntry('framework_base_path') . 'classes.php'; // Load file I/O handler -require($cfg->getConfigEntry('framework_base_path') . 'file_io.php'); +require $cfg->getConfigEntry('framework_base_path') . 'file_io.php'; // Load database layer -require($cfg->getConfigEntry('framework_base_path') . 'database.php'); +require $cfg->getConfigEntry('framework_base_path') . 'database.php'; // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); $application = 'shipsimu'; // Load more includes -require($cfg->getConfigEntry('root_base_path') . 'application/shipsimu/loader.php'); +require $cfg->getConfigEntry('root_base_path') . 'application/shipsimu/loader.php'; // Wir tun hier so, als waere schon das Reederei-Objekt generiert und wir wollen // jetzt die Personalliste wiederherstellen -- 2.39.5