From 4e95c4e90f08f67f43591eaaa0c006f923d8bacf Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sun, 26 Mar 2017 16:39:13 +0200 Subject: [PATCH] Continued with rewrites: - rewrote bootstrap to a more easier way, still index.php will contain a class - this class has a method to detect the framework's path on common places - splitted application_base_path and framework_base_path, was only base_path before MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- application/tests/init.php | 2 +- framework/bootstrap/bootstrap.inc.php | 32 +++++++++++ .../bootstrap/class_BootstrapFramework.php | 27 ++++++++-- framework/{config.php => config.inc.php} | 28 +++++----- framework/database.php | 9 ++-- framework/includes.php | 2 +- framework/loader/class_ClassLoader.php | 17 +++--- .../backend/class_CachedLocalFileDatabase.php | 8 +-- .../stacks/class_FileStackFactory.php | 2 +- .../classes/language/class_LanguageSystem.php | 7 ++- .../template/class_BaseTemplateEngine.php | 2 +- .../console/class_ConsoleTemplateEngine.php | 7 ++- .../html/class_HtmlTemplateEngine.php | 7 ++- .../image/class_ImageTemplateEngine.php | 9 ++-- .../mail/class_MailTemplateEngine.php | 7 ++- .../menu/class_MenuTemplateEngine.php | 17 +++--- .../compressor/class_CompressorChannel.php | 2 +- framework/selector.php | 2 +- index.php | 54 +++++++++---------- tests/ConfigTest.php | 4 +- tests/RegistryTest.php | 4 +- tests/RequestTest.php | 4 +- tests/Test.php | 4 +- tests/old/contract-test.php | 10 ++-- tests/old/loader-test.php | 10 ++-- tests/old/personell-test.php | 10 ++-- 26 files changed, 174 insertions(+), 113 deletions(-) create mode 100644 framework/bootstrap/bootstrap.inc.php rename framework/{config.php => config.inc.php} (94%) diff --git a/application/tests/init.php b/application/tests/init.php index 77c9fb87..29dfc167 100644 --- a/application/tests/init.php +++ b/application/tests/init.php @@ -37,7 +37,7 @@ ApplicationHelper::createDebugInstance('ApplicationHelper'); // This application needs a database connection then we have to simply include // the framework/database.php script -require($cfg->getConfigEntry('base_path') . 'framework/database.php'); +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 new file mode 100644 index 00000000..4c2ebd42 --- /dev/null +++ b/framework/bootstrap/bootstrap.inc.php @@ -0,0 +1,32 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * 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 . + */ + +// Load very basic classes, required to bootstrap +require(__DIR__ . '/class_BootstrapFramework.php'); + +// Bootstrap framework +BootstrapFramework::doBootstrap(); diff --git a/framework/bootstrap/class_BootstrapFramework.php b/framework/bootstrap/class_BootstrapFramework.php index ee8b6b95..565f3c8b 100644 --- a/framework/bootstrap/class_BootstrapFramework.php +++ b/framework/bootstrap/class_BootstrapFramework.php @@ -1,4 +1,10 @@ . */ -class BootstrapFramework { +final class BootstrapFramework { /** * Private constructor, no instance is needed from this class as only * static methods exist. @@ -29,7 +35,20 @@ class BootstrapFramework { private function __construct () { // Prevent making instances from this "utilities" class } -} -// [EOF] -?> + /** + * Does the actual bootstrap + * + * @return void + */ + 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'); + + // Load main configuration + require(ApplicationEntryPoint::detectFrameworkPath() . 'config.inc.php'); + } + +} diff --git a/framework/config.php b/framework/config.inc.php similarity index 94% rename from framework/config.php rename to framework/config.inc.php index 28803fef..1ea33974 100644 --- a/framework/config.php +++ b/framework/config.inc.php @@ -1,6 +1,7 @@ . */ -// Load very basic classes, required to bootstrap -require(ApplicationEntryPoint::detectCorePath() . '/framework/main/interfaces/class_FrameworkInterface.php'); -require(ApplicationEntryPoint::detectCorePath() . '/framework/main/interfaces/registry/class_Registerable.php'); -require(ApplicationEntryPoint::detectCorePath() . '/framework/config/class_FrameworkConfiguration.php'); - // Get a new configuration instance $cfg = FrameworkConfiguration::getSelfInstance(); -// CFG: SERVER-PATH -$cfg->setConfigEntry('base_path', ApplicationEntryPoint::detectCorePath() . '/'); +// CFG: ROOT-BASE-PATH +$cfg->setConfigEntry('root_base_path', BootstrapFramework::detectRootPath() . '/'); + +// CFG: CORE-BASE-PATH +$cfg->setConfigEntry('framework_base_path', ApplicationEntryPoint::detectFrameworkPath()); // CFG: BASE-URL $cfg->setConfigEntry('base_url', $cfg->detectBaseUrl()); // CFG: DATABASE-TYPE -$cfg->setConfigEntry('db_type', 'lfdb'); +$cfg->setConfigEntry('database_type', 'lfdb'); -// CFG: LOCAL-DB-PATH -$cfg->setConfigEntry('local_db_path', $cfg->getConfigEntry('base_path') . 'db/'); +// CFG: LOCAL-DATABASE-PATH +$cfg->setConfigEntry('local_database_path', $cfg->getConfigEntry('root_base_path') . 'db/'); // CFG: TIME-ZONE $cfg->setDefaultTimezone('Europe/Berlin'); @@ -77,16 +76,13 @@ $cfg->setConfigEntry('entry_method', 'entryPoint'); $cfg->setConfigEntry('tpl_base_path', 'templates/'); // CFG: LANGUAGE-BASE-PATH -$cfg->setConfigEntry('lang_base_path', 'framework/language/'); +$cfg->setConfigEntry('language_base_path', 'language/'); // CFG: COMPRESSOR-BASE-PATH -$cfg->setConfigEntry('compressor_base_path', 'framework/main/classes/compressor/'); +$cfg->setConfigEntry('compressor_base_path', 'main/classes/compressor/'); // CFG: APPLICATION-BASE-PATH -$cfg->setConfigEntry('application_base_path', 'application/'); - -// CFG: APPLICATION-PATH -$cfg->setConfigEntry('application_path', $cfg->getConfigEntry('base_path') . $cfg->getConfigEntry('application_base_path')); +$cfg->setConfigEntry('application_base_path', FrameworkBootstrap::detectApplicationBasePath()); // CFG: COMPILE-OUTPUT-PATH $cfg->setConfigEntry('compile_output_path', 'templates/_compiled/'); diff --git a/framework/database.php b/framework/database.php index 6249535f..2a13ed54 100644 --- a/framework/database.php +++ b/framework/database.php @@ -2,6 +2,7 @@ // Import framework stuff use CoreFramework\Configuration\FrameworkConfiguration; use CoreFramework\Connection\Database\DatabaseConnection; +use CoreFramework\EntryPoint\ApplicationEntryPoint; use CoreFramework\Object\BaseFrameworkSystem; use CoreFramework\Middleware\Debug\DebugMiddleware; @@ -35,9 +36,9 @@ $databaseInstance = NULL; // Generate FQFN for the database layer $fqfn = sprintf( - '%sframework/database/lib-%s.php', - FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path'), - FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type') + '%sdatabase/lib-%s.php', + FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path'), + FrameworkConfiguration::getSelfInstance()->getConfigEntry('database_type') ); // Load the database layer include @@ -47,7 +48,7 @@ if (BaseFrameworkSystem::isReadableFile($fqfn)) { } else { // Layer is missing! ApplicationEntryPoint::app_exit(sprintf('[Main:] Database layer is missing! (%s) -> R.I.P.', - FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type') + FrameworkConfiguration::getSelfInstance()->getConfigEntry('database_type') )); } diff --git a/framework/includes.php b/framework/includes.php index 806be049..3764ca73 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('base_path') . 'framework/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 05603620..bc37b2ad 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -4,7 +4,6 @@ namespace CoreFramework\Loader; // Import framework stuff use CoreFramework\Configuration\FrameworkConfiguration; -use CoreFramework\EntryPoint\ApplicationEntryPoint; use CoreFramework\Object\BaseFrameworkSystem; // Import SPL stuff @@ -217,8 +216,8 @@ class ClassLoader { // Generate full path from it $pathName = realpath(sprintf( - '%s/framework/main/%s/', - $cfg->getConfigEntry('base_path'), + '%smain/%s/', + $cfg->getConfigEntry('framework_base_path'), $shortPath )); @@ -265,7 +264,7 @@ class ClassLoader { // Create path name $pathName = realpath(sprintf( '%s/%s/%s', - $cfg->getConfigEntry('application_path'), + $cfg->getConfigEntry('application_base_path'), $cfg->getConfigEntry('app_name'), $shortPath )); @@ -304,7 +303,7 @@ class ClassLoader { // Create path name $pathName = realpath(sprintf( '%s/%s', - $cfg->getConfigEntry('base_path'), + $cfg->getConfigEntry('framework_base_path'), $shortPath )); @@ -374,7 +373,7 @@ class ClassLoader { /** * Scans recursively a local path for class files which must have a prefix and a suffix as given by $this->suffix and $this->prefix * - * @param $basePath The relative base path to 'base_path' constant for all classes + * @param $basePath The relative base path to 'framework_base_path' constant for all classes * @param $ignoreList An optional list (array forced) of directory and file names which shall be ignored * @return void */ @@ -465,7 +464,7 @@ class ClassLoader { $this->prefix = 'config-'; // Set base directory - $basePath = $this->configInstance->getConfigEntry('base_path') . 'framework/config/'; + $basePath = $this->configInstance->getConfigEntry('framework_base_path') . 'config/'; // Load all classes from the config directory $this->scanClassPath($basePath); @@ -489,8 +488,8 @@ class ClassLoader { // Construct the FQFN for the cache if (!defined('DEVELOPER')) { - $this->listCacheFQFN = $this->configInstance->getConfigEntry('local_db_path') . 'list-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; - $this->classCacheFQFN = $this->configInstance->getConfigEntry('local_db_path') . 'class-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; + $this->listCacheFQFN = $this->configInstance->getConfigEntry('local_database_path') . 'list-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; + $this->classCacheFQFN = $this->configInstance->getConfigEntry('local_database_path') . 'class-' . $this->configInstance->getConfigEntry('app_name') . '.cache'; } // END - if // Set suffix and prefix from configuration diff --git a/framework/main/classes/database/backend/class_CachedLocalFileDatabase.php b/framework/main/classes/database/backend/class_CachedLocalFileDatabase.php index fac9b9ea..a2f65b40 100644 --- a/framework/main/classes/database/backend/class_CachedLocalFileDatabase.php +++ b/framework/main/classes/database/backend/class_CachedLocalFileDatabase.php @@ -257,7 +257,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac */ private function generateFqfnFromDataSet (Criteria $dataSetInstance, $rowName) { // This is the FQFN - $fqfn = $this->getConfigInstance()->getConfigEntry('local_db_path') . $dataSetInstance->getTableName() . '/' . $rowName . '.' . $this->getFileExtension(); + $fqfn = $this->getConfigInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . '/' . $rowName . '.' . $this->getFileExtension(); // Return it return $fqfn; @@ -359,7 +359,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac $resultData = NULL; // Create full path name - $pathName = $this->getConfigInstance()->getConfigEntry('local_db_path') . $tableName . '/'; + $pathName = $this->getConfigInstance()->getConfigEntry('local_database_path') . $tableName . '/'; /* * A 'select' query is not that easy on local files, so first try to @@ -502,7 +502,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac */ public function queryUpdateDataSet (StoreableCriteria $dataSetInstance) { // Create full path name - $pathName = $this->getConfigInstance()->getConfigEntry('local_db_path') . $dataSetInstance->getTableName() . '/'; + $pathName = $this->getConfigInstance()->getConfigEntry('local_database_path') . $dataSetInstance->getTableName() . '/'; // Try all the requests try { @@ -646,7 +646,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE: tableName=' . $tableName . ' - CALLED!'); // Create full path name - $pathName = $this->getConfigInstance()->getConfigEntry('local_db_path') . $tableName . '/'; + $pathName = $this->getConfigInstance()->getConfigEntry('local_database_path') . $tableName . '/'; // Try all the requests try { diff --git a/framework/main/classes/factories/stacks/class_FileStackFactory.php b/framework/main/classes/factories/stacks/class_FileStackFactory.php index 4394ab4c..957810fb 100644 --- a/framework/main/classes/factories/stacks/class_FileStackFactory.php +++ b/framework/main/classes/factories/stacks/class_FileStackFactory.php @@ -50,7 +50,7 @@ class FileStackFactory extends ObjectFactory { public static final function createFileStackInstance ($prefix, $stackName) { // Construct file stack name $stackFileName = sprintf('%s%s/%s.%s', - FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path'), + FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path'), FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_file_stacks_path'), $stackName, FrameworkConfiguration::getSelfInstance()->getConfigEntry('file_stacks_extension') diff --git a/framework/main/classes/language/class_LanguageSystem.php b/framework/main/classes/language/class_LanguageSystem.php index 0c2875ac..6e775009 100644 --- a/framework/main/classes/language/class_LanguageSystem.php +++ b/framework/main/classes/language/class_LanguageSystem.php @@ -85,10 +85,9 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, $applicationInstance = Registry::getRegistry()->getInstance('app'); // 2) Try to build it - $languageBasePath = sprintf('%sapplication/%s/language/', - $langInstance->getConfigInstance()->getConfigEntry('base_path'), - // Don't allow any underscores/dashes in application names - str_replace(array('_', '-'), array('', ''), $applicationInstance->getAppShortName()) + $languageBasePath = sprintf('%s%s/language/', + $langInstance->getConfigInstance()->getConfigEntry('application_base_path'), + $applicationInstance->getAppShortName() ); } // END - if diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index 9cb1411b..cb071257 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -690,7 +690,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * template paths comes from an older time. */ $fqfn = sprintf('%s%s%s%s/%s%s', - $this->getConfigInstance()->getConfigEntry('base_path'), + $this->getConfigInstance()->getConfigEntry('application_base_path'), $this->getTemplateBasePath(), $this->getGenericBasePath(), $this->getTemplateType(), diff --git a/framework/main/classes/template/console/class_ConsoleTemplateEngine.php b/framework/main/classes/template/console/class_ConsoleTemplateEngine.php index e6305d81..0464ce97 100644 --- a/framework/main/classes/template/console/class_ConsoleTemplateEngine.php +++ b/framework/main/classes/template/console/class_ConsoleTemplateEngine.php @@ -62,7 +62,7 @@ class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTem $applicationInstance = Registry::getRegistry()->getInstance('app'); // Determine base path - $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/'; + $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/'; // Is the base path valid? if (empty($templateBasePath)) { @@ -87,7 +87,10 @@ class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTem $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension')); // Absolute output path for compiled templates - $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')); + $templateInstance->setCompileOutputPath(sprintf('%s%s/', + $templateBasePath, + $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path') + )); // Return the prepared instance return $templateInstance; diff --git a/framework/main/classes/template/html/class_HtmlTemplateEngine.php b/framework/main/classes/template/html/class_HtmlTemplateEngine.php index 1149efff..763d88c2 100644 --- a/framework/main/classes/template/html/class_HtmlTemplateEngine.php +++ b/framework/main/classes/template/html/class_HtmlTemplateEngine.php @@ -62,7 +62,7 @@ class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTempla $applicationInstance = Registry::getRegistry()->getInstance('app'); // Determine base path - $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/'; + $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/'; // Is the base path valid? if (empty($templateBasePath)) { @@ -87,7 +87,10 @@ class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTempla $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension')); // Absolute output path for compiled templates - $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')); + $templateInstance->setCompileOutputPath(sprintf('%s%s/', + $templateBasePath, + $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path') + )); // Return the prepared instance return $templateInstance; diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index 9f4cd8a9..42660810 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -98,7 +98,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $applicationInstance = Registry::getRegistry()->getInstance('app'); // Determine base path - $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/'; + $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/'; // Is the base path valid? if (empty($templateBasePath)) { @@ -123,7 +123,10 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension')); // Absolute output path for compiled templates - $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')); + $templateInstance->setCompileOutputPath(sprintf('%s%s/', + $templateBasePath, + $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path') + )); // Return the prepared instance return $templateInstance; @@ -474,7 +477,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl public function getImageCacheFqfn () { // Get the FQFN ready $fqfn = sprintf('%s%s%s/%s.%s', - $this->getConfigInstance()->getConfigEntry('base_path'), + $this->getConfigInstance()->getConfigEntry('framework_base_path'), $this->getGenericBasePath(), 'images/_cache', md5( diff --git a/framework/main/classes/template/mail/class_MailTemplateEngine.php b/framework/main/classes/template/mail/class_MailTemplateEngine.php index 7ff55f30..763d4602 100644 --- a/framework/main/classes/template/mail/class_MailTemplateEngine.php +++ b/framework/main/classes/template/mail/class_MailTemplateEngine.php @@ -92,7 +92,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla $applicationInstance = Registry::getRegistry()->getInstance('app'); // Determine base path - $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/'; + $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/'; // Is the base path valid? if (empty($templateBasePath)) { @@ -117,7 +117,10 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension')); // Absolute output path for compiled templates - $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')); + $templateInstance->setCompileOutputPath(sprintf('%s%s/', + $templateBasePath, + $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path') + )); // Return the prepared instance return $templateInstance; diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index c5601b4c..316f1518 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -151,7 +151,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla $applicationInstance = Registry::getRegistry()->getInstance('app'); // Determine base path - $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/'; + $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/'; // Is the base path valid? if (empty($templateBasePath)) { @@ -176,7 +176,10 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('menu_template_extension')); // Absolute output path for compiled templates - $templateInstance->setCompileOutputPath($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')); + $templateInstance->setCompileOutputPath(sprintf('%s%s/', + $templateBasePath, + $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path') + )); // Set the menu instance $templateInstance->setMenuInstance($menuInstance); @@ -866,11 +869,13 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @return $fqfn Full-qualified file name of the menu cache */ public function getMenuCacheFqfn () { + // Get the application instance from registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + // Get the FQFN ready - $fqfn = sprintf('%s%s%s/%s.%s', - $this->getConfigInstance()->getConfigEntry('base_path'), - $this->getGenericBasePath(), - 'menus/_cache', + $fqfn = sprintf('%s%smenus/_cache/%s.%s', + $this->getConfigInstance()->getConfigEntry('application_base_path'), + $applicationInstance->getAppShortName(), md5( $this->getMenuInstance()->getMenuName() . ':' . $this->__toString() . ':' . diff --git a/framework/main/middleware/compressor/class_CompressorChannel.php b/framework/main/middleware/compressor/class_CompressorChannel.php index 1e7bf82a..0baffa55 100644 --- a/framework/main/middleware/compressor/class_CompressorChannel.php +++ b/framework/main/middleware/compressor/class_CompressorChannel.php @@ -62,7 +62,7 @@ class CompressorChannel extends BaseMiddleware implements Registerable { ) { // Init base directory $baseDir = - $compressorInstance->getConfigInstance()->getConfigEntry('base_path') . + $compressorInstance->getConfigInstance()->getConfigEntry('framework_base_path') . $compressorInstance->getConfigInstance()->getConfigEntry('compressor_base_path'); // Get a directory pointer diff --git a/framework/selector.php b/framework/selector.php index 59abbe55..abedae92 100644 --- a/framework/selector.php +++ b/framework/selector.php @@ -41,7 +41,7 @@ $configAppIncludes = array( ); // Cache base path/file here -$basePathFile = FrameworkConfiguration::getSelfInstance()->getConfigEntry('application_path') . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_name'); +$basePathFile = FrameworkConfiguration::getSelfInstance()->getConfigEntry('application_base_path') . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_name'); // Is the directory there? if (!is_dir($basePathFile)) { diff --git a/index.php b/index.php index e058edad..ecf66b48 100644 --- a/index.php +++ b/index.php @@ -10,6 +10,9 @@ use CoreFramework\Localization\LanguageSystem; use CoreFramework\Loader\ClassLoader; use CoreFramework\Generic\FrameworkException; +// Import SPL stuff +use \Exception; + /** * The main class with the entry point to the whole application. This class * "emulates" Java's entry point call. Additionally it covers local @@ -39,9 +42,9 @@ use CoreFramework\Generic\FrameworkException; */ final class ApplicationEntryPoint { /** - * Core path + * Framework path */ - private static $corePath = ''; + private static $frameworkPath = ''; /** * The application's emergency exit @@ -177,18 +180,18 @@ final class ApplicationEntryPoint { } /** - * Determines the correct absolute path for all includes only once per run. - * Other calls of this method are being "cached". This is done by checking - * a small list of common paths where the framework can reside and check if - * framework/config.php can be found. + * Determines the correct absolute path for the framework. A set of common + * paths is being tested (first most common for applications, second when + * core tests are being executed and third/forth if the framework has been + * cloned there). * - * @return $corePath Base path (core) for all includes + * @return $frameworkPath Path for framework */ - protected static final function detectCorePath () { + public static final function detectFrameworkPath () { // Is it not set? - if (empty(self::$corePath)) { + if (empty(self::$frameworkPath)) { // Auto-detect core path (first application-common) - foreach (array('core', '.') as $possiblePath) { + foreach (array('core', '.', '/usr/local/share/php/core', '/usr/share/php/core') as $possiblePath) { // Create full path for testing $realPath = realpath($possiblePath); @@ -201,9 +204,9 @@ final class ApplicationEntryPoint { continue; } // END - if - // First create full-qualified file name (FQFN) to framework/config.php + // First create full-qualified file name (FQFN) to framework/config.inc.php $fqfn = sprintf( - '%s%sframework%sconfig.php', + '%s%sframework%sconfig.inc.php', $realPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, @@ -211,21 +214,27 @@ 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)) { // Found one - self::$corePath = $realPath; + self::$frameworkPath = $realPath . '/framework/'; // Abort here break; } // END - if } // END - foreach + + // Able to find? + if (!is_dir(self::$frameworkPath)) { + // Is no directory + throw new Exception('Cannot find framework.'); + } // END - if } // END - if // Return it - return self::$corePath; + return self::$frameworkPath; } /** @@ -237,22 +246,11 @@ final class ApplicationEntryPoint { * @return void */ public static final function main () { - // Load config file, this no longer provides $cfg - require(self::detectCorePath() . '/framework/config.php'); + // Load bootstrap file + require(self::detectFrameworkPath() . 'bootstrap/bootstrap.inc.php'); // Get a new configuration instance $cfg = FrameworkConfiguration::getSelfInstance(); - - // Load bootstrap class - require($cfg->getConfigEntry('base_path') . 'framework/bootstrap/class_BootstrapFramework.php'); - - // ----- Below is deprecated ----- - - // Load all include files - require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); - - // Include the application selector - require($cfg->getConfigEntry('base_path') . 'framework/selector.php'); } } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 6e2c34b8..968452a5 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -8,10 +8,10 @@ print (basename(__FILE__).": Init...\n"); require(dirname(dirname(__FILE__)) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); diff --git a/tests/RegistryTest.php b/tests/RegistryTest.php index 7031b2a3..846ec55c 100644 --- a/tests/RegistryTest.php +++ b/tests/RegistryTest.php @@ -8,10 +8,10 @@ print (basename(__FILE__).": Init...\n"); require(dirname(dirname(__FILE__)) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index a32dfe78..80d78e47 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -8,10 +8,10 @@ print (basename(__FILE__).": Init...\n"); require(dirname(dirname(__FILE__)) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); diff --git a/tests/Test.php b/tests/Test.php index 078f0bb7..2e8e6565 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -8,10 +8,10 @@ print (basename(__FILE__).": Init...\n"); require(dirname(dirname(__FILE__)) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); diff --git a/tests/old/contract-test.php b/tests/old/contract-test.php index 9a1d55cc..b4de26a7 100644 --- a/tests/old/contract-test.php +++ b/tests/old/contract-test.php @@ -9,23 +9,23 @@ define('TEST_MODE', true); require(dirname(dirname(dirname(__FILE__))) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Load file I/O handler -require($cfg->getConfigEntry('base_path') . 'framework/file_io.php'); +require($cfg->getConfigEntry('framework_base_path') . 'file_io.php'); // Load database layer -require($cfg->getConfigEntry('base_path') . 'framework/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('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 b72865d4..ef18401a 100644 --- a/tests/old/loader-test.php +++ b/tests/old/loader-test.php @@ -9,23 +9,23 @@ define('TEST_MODE', true); require(dirname(dirname(dirname(__FILE__))) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Load file I/O handler -require($cfg->getConfigEntry('base_path') . 'framework/file_io.php'); +require($cfg->getConfigEntry('framework_base_path') . 'file_io.php'); // Load database layer -require($cfg->getConfigEntry('base_path') . 'framework/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('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 be1271b0..df2ef254 100644 --- a/tests/old/personell-test.php +++ b/tests/old/personell-test.php @@ -9,23 +9,23 @@ define('TEST_MODE', true); require(dirname(dirname(dirname(__FILE__))) . '/framework/config.php'); // Load all include files -require($cfg->getConfigEntry('base_path') . 'framework/includes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'includes.php'); // Load all game classes -require($cfg->getConfigEntry('base_path') . 'framework/classes.php'); +require($cfg->getConfigEntry('framework_base_path') . 'classes.php'); // Load file I/O handler -require($cfg->getConfigEntry('base_path') . 'framework/file_io.php'); +require($cfg->getConfigEntry('framework_base_path') . 'file_io.php'); // Load database layer -require($cfg->getConfigEntry('base_path') . 'framework/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('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