X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fbootstrap%2Fclass_FrameworkBootstrap.php;h=c8141169428e144df086ccd36d49b4a01fcee8e4;hp=047bcf894dd20be7d21d0841d90863cab3a19e80;hb=refs%2Fheads%2Fmaster;hpb=a60894f1d6ef33613d2d0351075aa07aa257f304 diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index 047bcf89..004b4c6f 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -8,16 +8,18 @@ use Org\Mxchange\CoreFramework\Connection\Database\DatabaseConnection; use Org\Mxchange\CoreFramework\Connector\Database\DatabaseConnector; use Org\Mxchange\CoreFramework\Console\Tools\ConsoleTools; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; -use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; +use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; +use Org\Mxchange\CoreFramework\Localization\ManageableLanguage; use Org\Mxchange\CoreFramework\Loader\ClassLoader; use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; -use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Response\Responseable; +use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils; // Import SPL stuff use \BadMethodCallException; @@ -29,7 +31,7 @@ use \SplFileInfo; * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -73,11 +75,16 @@ final class FrameworkBootstrap { */ private static $databaseInstance = NULL; + /** + * Language system instance + */ + private static $languageInstance = NULL; + /* * Includes applications may have. They will be tried in the given order, * some will become soon deprecated. */ - private static $configAppIncludes = array( + private static $configAppIncludes = [ // The ApplicationHelper class (required) 'class_ApplicationHelper' => 'required', // Some debugging stuff (optional but can be committed) @@ -96,7 +103,17 @@ final class FrameworkBootstrap { 'init' => 'deprecated', // Application starter (deprecated) 'starter' => 'deprecated', - ); + ]; + + /** + * Detected application's name + */ + private static $detectedApplicationName; + + /** + * Detected application's full path + */ + private static $detectedApplicationPath; /** * Private constructor, no instance is needed from this class as only @@ -116,12 +133,30 @@ final class FrameworkBootstrap { if (is_null(self::$configurationInstance)) { // Init new instance self::$configurationInstance = new FrameworkConfiguration(); - } // END - if + } // Return it return self::$configurationInstance; } + /** + * Getter for detected application name + * + * @return $detectedApplicationName Detected name of application + */ + public static function getDetectedApplicationName () { + return self::$detectedApplicationName; + } + + /** + * Getter for detected application's full path + * + * @return $detectedApplicationPath Detected full path of application + */ + public static function getDetectedApplicationPath () { + return self::$detectedApplicationPath; + } + /** * "Getter" to get response/request type from analysis of the system. * @@ -135,7 +170,7 @@ final class FrameworkBootstrap { if (isset($_SERVER['HTTP_HOST'])) { // Then it is a HTML response/request. $requestType = 'html'; - } // END - if + } // Return it return $requestType; @@ -151,30 +186,36 @@ final class FrameworkBootstrap { */ public static function isReachableFilePath (SplFileInfo $fileInstance) { // Is not reachable by default + //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, get_class($fileInstance)); $isReachable = false; // Get open_basedir parameter $openBaseDir = trim(ini_get('open_basedir')); // Is it set? + //* NOISY-DEBUG: */ printf('[%s:%d]: openBaseDir=%s' . PHP_EOL, __METHOD__, __LINE__, $openBaseDir); if (!empty($openBaseDir)) { // Check all entries foreach (explode(PATH_SEPARATOR, $openBaseDir) as $dir) { // Check on existence + //* NOISY-DEBUG: */ printf('[%s:%d]: dir=%s' . PHP_EOL, __METHOD__, __LINE__, $dir); if (substr($fileInstance->getPathname(), 0, strlen($dir)) == $dir) { // Is reachable $isReachable = true; // Abort lookup as it has been found in open_basedir + //* NOISY-DEBUG: */ printf('[%s:%d]: BREAK!' . PHP_EOL, __METHOD__, __LINE__); break; - } // END - if - } // END - foreach + } + } } else { // If open_basedir is not set, all is allowed + //* NOISY-DEBUG: */ printf('[%s:%d]: All is allowed - BREAK!' . PHP_EOL, __METHOD__, __LINE__); $isReachable = true; } // Return status + //* NOISY-DEBUG: */ printf('[%s:%d]: isReachable=%d - EXIT' . PHP_EOL, __METHOD__, __LINE__, intval($isReachable)); return $isReachable; } @@ -186,10 +227,8 @@ final class FrameworkBootstrap { * @return $isReadable Whether the file is readable (and therefor exists) */ public static function isReadableFile (SplFileInfo $fileInstance) { - // Default is not readable - $isReadable = false; - // Check if it is a file and readable + //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, get_class($fileInstance)); $isReadable = ( ( self::isReachableFilePath($fileInstance) @@ -201,6 +240,7 @@ final class FrameworkBootstrap { ); // Return status + //* NOISY-DEBUG: */ printf('[%s:%d]: isReadable=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($isReadable)); return $isReadable; } @@ -212,14 +252,18 @@ final class FrameworkBootstrap { * @throws InvalidArgumentException If file was not found or not readable or deprecated */ public static function loadInclude (SplFileInfo $fileInstance) { - // Trace message - //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance); - // Should be there ... + //* NOISY-DEBUG: */ printf('[%s:%d]: fileInstance=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $fileInstance->__toString()); if (!self::isReadableFile($fileInstance)) { // Abort here throw new InvalidArgumentException(sprintf('Cannot find fileInstance.pathname=%s.', $fileInstance->getPathname())); - } // END - if + } elseif (!$fileInstance->isFile()) { + // Not a file + throw new InvalidArgumentException(sprintf('fileInstance.pathname=%s is not a file', $fileInstance->getPathname())); + } elseif (substr($fileInstance->__toString(), -4, 4) != '.php') { + // Not PHP script + throw new InvalidArgumentException(sprintf('fileInstance.pathname=%s is not a PHP script', $fileInstance->getPathname())); + } // Load it require_once $fileInstance->getPathname(); @@ -229,20 +273,28 @@ final class FrameworkBootstrap { } /** - * Does the actual bootstrap + * Does the actual bootstrap. I think the amount of statically loaded + * include files cannot be reduced here as those files are need to early + * in the bootstrap phase. If you can find an other solution than this, with + * lesser "static includes" (means not loaded by the class loader), please + * let me know. * * @return void */ public static function doBootstrap () { // Load basic include files to continue bootstrapping + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sclass_FrameworkInterface.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR))); self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sclass_BaseFrameworkSystem.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR))); - self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sutils%sclass_StringUtils.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR))); + self::loadInclude(new SplFileInfo(sprintf('%smain%sclasses%sutils%sstrings%sclass_StringUtils.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR))); self::loadInclude(new SplFileInfo(sprintf('%smain%sinterfaces%sregistry%sclass_Registerable.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR))); self::loadInclude(new SplFileInfo(sprintf('%sconfig%sclass_FrameworkConfiguration.php', ApplicationEntryPoint::detectFrameworkPath(), DIRECTORY_SEPARATOR))); // Load global configuration self::loadInclude(new SplFileInfo(sprintf('%s%s', ApplicationEntryPoint::detectFrameworkPath(), 'config-global.php'))); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -259,11 +311,12 @@ final class FrameworkBootstrap { * 1) Load class loader and scan framework classes, interfaces and * exceptions. */ + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); self::scanFrameworkClasses(); /* * 2) Determine the request type, console or web and store request and - * response here. This also initializes the request instance will + * response here. This also initializes the request instance with * all given parameters (see doc-tag for possible sources of * parameters). */ @@ -275,6 +328,9 @@ final class FrameworkBootstrap { * found, continue below with next step. */ self::validateApplicationParameter(); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -285,45 +341,51 @@ final class FrameworkBootstrap { * @return void */ public static function prepareApplication () { - // Configuration entry 'detected_app_name' must be set, get it here, including full 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 * warning at the user. */ + //* NOISY-DEBUG: */ printf('[%s:%d]: self::configAppIncludes()=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, count(self::$configAppIncludes)); foreach (self::$configAppIncludes as $fileName => $status) { // Construct file instance - $fileInstance = new SplFileInfo(sprintf('%s%s.php', $fullPath, $fileName)); + //* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status); + $fileInstance = new SplFileInfo(sprintf('%s%s.php', self::getDetectedApplicationPath(), $fileName)); // Determine if this file is wanted/readable/deprecated if (($status == 'required') && (!self::isReadableFile($fileInstance))) { // Nope, required file cannot be found/read from - ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', $application, $fileInstance->getBasename())); + ApplicationEntryPoint::exitApplication(sprintf('Application "%s" does not have required file "%s.php". Please add it.', self::getDetectedApplicationName(), $fileInstance->getBasename())); } elseif (($fileInstance->isFile()) && (!$fileInstance->isReadable())) { // Found, not readable file - ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), $application)); + ApplicationEntryPoint::exitApplication(sprintf('File "%s.php" from application "%s" cannot be read. Please fix CHMOD.', $fileInstance->getBasename(), self::getDetectedApplicationName())); } elseif (($status != 'required') && (!self::isReadableFile($fileInstance))) { // Not found but optional/deprecated file, skip it + //* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s - SKIPPED!' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status); continue; } // Is the file deprecated? if ($status == 'deprecated') { // Issue warning - trigger_error(sprintf('Deprecated file "%s.php" found, will not load it to avoid problems. Please remove it from your application "%s" to avoid this warning.', $fileName, $application), E_USER_WARNING); + trigger_error(sprintf('Deprecated file "%s.php" found, will not load it to avoid problems. Please remove it from your application "%s" to avoid this warning.', $fileName, self::getDetectedApplicationName()), E_USER_WARNING); // Skip loading deprecated file continue; - } // END - if + } // Load it + //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking self::loadInclude(%s) ...' . PHP_EOL, __METHOD__, __LINE__, $fileInstance->__toString()); self::loadInclude($fileInstance); - } // END - foreach + } + + // After this, sort the configuration array + self::getConfigurationInstance()->sortConfigurationArray(); // Scan for application's classes, exceptions and interfaces ClassLoader::scanApplicationClasses(); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -333,69 +395,77 @@ final class FrameworkBootstrap { * @return void */ public static function startApplication () { - // Configuration entry 'detected_app_name' must be set, get it here - $application = self::getConfigurationInstance()->getConfigEntry('detected_app_name'); - // Is there an application helper instance? + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $applicationInstance = call_user_func_array( - array( + [ 'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper', 'getSelfInstance' - ), array() + ], [] ); // Some sanity checks + //* NOISY-DEBUG: */ printf('[%s:%d]: applicationInstance=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationInstance->__toString()); if ((empty($applicationInstance)) || (is_null($applicationInstance))) { // Something went wrong! ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application %s could not be launched because the helper class %s is not loaded.', - $application, + self::getDetectedApplicationName(), 'Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper' )); } elseif (!is_object($applicationInstance)) { // No object! ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application %s could not be launched because 'app' is not an object (%s).', - $application, + self::getDetectedApplicationName(), gettype($applicationInstance) )); } elseif (!($applicationInstance instanceof ManageableApplication)) { // Missing interface ApplicationEntryPoint::exitApplication(sprintf('[Main:] The application %s could not be launched because 'app' is lacking required interface ManageableApplication.', - $application + self::getDetectedApplicationName() )); } // Now call all methods in one go - foreach (array('setupApplicationData', 'initApplication', 'launchApplication') as $methodName) { - // Debug message - //*NOISY-DEBUG: */ printf('[%s:%d]: Calling methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName); - + //* NOISY-DEBUG: */ printf('[%s:%d]: Initializing application ...' . PHP_EOL, __METHOD__, __LINE__); + foreach (['setupApplicationData', 'initApplication', 'launchApplication'] as $methodName) { // Call method - call_user_func(array($applicationInstance, $methodName)); - } // END - foreach + //*NOISY-DEBUG: */ printf('[%s:%d]: Invoking methodName=%s ...' . PHP_EOL, __METHOD__, __LINE__, $methodName); + call_user_func([$applicationInstance, $methodName]); + } + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** * Initializes database instance, no need to double-call this method * * @return void + * @throws BadMethodCallException If this method was invoked twice */ public static function initDatabaseInstance () { // Get application instance + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $applicationInstance = ApplicationHelper::getSelfInstance(); // Is the database instance already set? + //* NOISY-DEBUG: */ printf('[%s:%d]: self::databaseInstance[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype(self::getDatabaseInstance())); if (self::getDatabaseInstance() instanceof DatabaseConnector) { // Yes, then abort here throw new BadMethodCallException('Method called twice.'); - } // END - if + } // Initialize database layer $databaseInstance = ObjectFactory::createObjectByConfiguredName(self::getConfigurationInstance()->getConfigEntry('database_type') . '_class'); // Prepare database instance - $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance); + $connectionInstance = DatabaseConnection::createDatabaseConnection($databaseInstance); // Set it in application helper + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting connectionInstance=%s ...' . PHP_EOL, __METHOD__, __LINE__, $connectionInstance->__toString()); self::setDatabaseInstance($connectionInstance); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -407,33 +477,40 @@ final class FrameworkBootstrap { */ public static function detectServerAddress () { // Is the entry set? + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); if (!isset(self::$serverAddress)) { // Is it set in $_SERVER? if (!empty($_SERVER['SERVER_ADDR'])) { // Set it from $_SERVER + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::serverAddress=%s from SERVER_ADDR ...' . PHP_EOL, __METHOD__, __LINE__, $_SERVER['SERVER_ADDR']); self::$serverAddress = $_SERVER['SERVER_ADDR']; } elseif (isset($_SERVER['SERVER_NAME'])) { // Resolve IP address + //* NOISY-DEBUG: */ printf('[%s:%d]: Resolving SERVER_NAME=%s ...' . PHP_EOL, __METHOD__, __LINE__, $_SERVER['SERVER_NAME']); $serverIp = ConsoleTools::resolveIpAddress($_SERVER['SERVER_NAME']); // Is it valid? + //* NOISY-DEBUG: */ printf('[%s:%d]: serverId[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($serverIp), $serverIp); if ($serverIp === false) { /* * Why is gethostbyname() returning the host name and not * false as many other PHP functions are doing? ;-( */ throw new UnknownHostnameException(sprintf('Cannot resolve "%s" to an IP address. Please fix your setup.', $_SERVER['SERVER_NAME'])); - } // END - if + } // Al fine, set it + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::serverAddress=%s from resolver ...' . PHP_EOL, __METHOD__, __LINE__, $serverAddress); self::$serverAddress = $serverIp; } else { // Run auto-detecting through console tools lib + //* NOISY-DEBUG: */ printf('[%s:%d]: Invoking ConsoleTools::acquireSelfIpAddress() ...' . PHP_EOL, __METHOD__, __LINE__); self::$serverAddress = ConsoleTools::acquireSelfIpAddress(); } - } // END - if + } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: self::serverAddress=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$serverAddress); return self::$serverAddress; } @@ -442,20 +519,14 @@ final class FrameworkBootstrap { * * @param $timezone The timezone string (e.g. Europe/Berlin) * @return $success If timezone was accepted - * @throws NullPointerException If $timezone is NULL * @throws InvalidArgumentException If $timezone is empty */ - public static function setDefaultTimezone ($timezone) { - // Is it null? - if (is_null($timezone)) { - // Throw NPE - throw new NullPointerException(NULL, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_string($timezone)) { - // Is not a string - throw new InvalidArgumentException(sprintf('timezone[]=%s is not a string', gettype($timezone))); - } elseif ((is_string($timezone)) && (empty($timezone))) { + public static function setDefaultTimezone (string $timezone) { + // Is it set? + //* NOISY-DEBUG: */ printf('[%s:%d]: timezone=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $timezone); + if (empty($timezone)) { // Entry is empty - throw new InvalidArgumentException('timezone is empty'); + throw new InvalidArgumentException('Parameter "timezone" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); } // Default success @@ -468,6 +539,7 @@ final class FrameworkBootstrap { $success = date_default_timezone_set($timezone); // Return status + //* NOISY-DEBUG: */ printf('[%s:%d]: success=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($success)); return $success; } @@ -478,6 +550,7 @@ final class FrameworkBootstrap { * @todo Test more fields */ public static function isHttpSecured () { + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); return ( ( ( @@ -502,18 +575,20 @@ final class FrameworkBootstrap { */ public static function detectBaseUrl () { // Initialize the URL + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $protocol = 'http'; // Do we have HTTPS? if (self::isHttpSecured()) { // Add the >s< for HTTPS $protocol = 'https'; - } // END - if + } // Construct the full URL and secure it against CSRF attacks $baseUrl = sprintf('%s://%s%s', $protocol, self::detectDomain(), self::detectScriptPath()); // Return the URL + //* NOISY-DEBUG: */ printf('[%s:%d]: baseUrl=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $baseUrl); return $baseUrl; } @@ -524,15 +599,17 @@ final class FrameworkBootstrap { */ public static function detectDomain () { // Full domain is localnet.invalid by default + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $fullDomain = 'localnet.invalid'; // Is the server name there? if (isset($_SERVER['SERVER_NAME'])) { // Detect the full domain $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES); - } // END - if + } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: fullDomain=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $fullDomain); return $fullDomain; } @@ -544,15 +621,17 @@ final class FrameworkBootstrap { */ public static function detectScriptPath () { // Default is empty + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $scriptPath = ''; // Is the scriptname set? if (isset($_SERVER['SCRIPT_NAME'])) { // Get dirname from it and replace back-slashes with slashes for lame OSes... $scriptPath = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME'])); - } // END - if + } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: scriptPath=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $scriptPath); return $scriptPath; } @@ -569,7 +648,8 @@ final class FrameworkBootstrap { * @return void */ private static function scanFrameworkClasses () { - // Include the class loader function + // Include class loader + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); require self::getConfigurationInstance()->getConfigEntry('framework_base_path') . 'loader/class_ClassLoader.php'; // Register auto-load function with the SPL @@ -577,6 +657,9 @@ final class FrameworkBootstrap { // Scan for all framework classes, exceptions and interfaces ClassLoader::scanFrameworkClasses(); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -587,13 +670,16 @@ final class FrameworkBootstrap { */ private static function determineRequestType () { // Determine request type + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); $request = self::getRequestTypeFromSystem(); $requestType = self::getRequestTypeFromSystem(); // Create a new request object - $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', BaseFrameworkSystem::convertToClassName($request))); + //* NOISY-DEBUG: */ printf('[%s:%d]: request=%s,requestType=%s' . PHP_EOL, __METHOD__, __LINE__, $request, $requestType); + $requestInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Request\%sRequest', StringUtils::convertToClassName($request))); // Remember request instance here + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting requestInstance=%s ...' . PHP_EOL, __METHOD__, __LINE__, $requestInstance->__toString()); self::setRequestInstance($requestInstance); // Do we have another response? @@ -601,14 +687,18 @@ final class FrameworkBootstrap { // Then use it $request = strtolower($requestInstance->getRequestElement('request')); $requestType = $request; - } // END - if + } // ... and a new response object - $responseClass = sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', BaseFrameworkSystem::convertToClassName($request)); - $responseInstance = ObjectFactory::createObjectByName($responseClass); + //* NOISY-DEBUG: */ printf('[%s:%d]: request=%s,requestType=%s - AFTER!' . PHP_EOL, __METHOD__, __LINE__, $request, $requestType); + $responseInstance = ObjectFactory::createObjectByName(sprintf('Org\Mxchange\CoreFramework\Response\%sResponse', StringUtils::convertToClassName($request))); // Remember response instance here + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting responseInstance=%s ...' . PHP_EOL, __METHOD__, __LINE__, $responseInstance->__toString()); self::setResponseInstance($responseInstance); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -618,6 +708,7 @@ final class FrameworkBootstrap { */ private static function validateApplicationParameter () { // Is the parameter set? + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); if (!self::getRequestInstance()->isRequestElementSet('app')) { /* * Don't continue here, the application 'selector' is no longer @@ -625,35 +716,43 @@ final class FrameworkBootstrap { * application (by user). */ ApplicationEntryPoint::exitApplication('No application specified. Please provide a parameter "app" and retry.'); - } // END - if + } // Get it for local usage - $application = self::getRequestInstance()->getRequestElement('app'); + $applicationName = self::getRequestInstance()->getRequestElement('app'); // Secure it, by keeping out tags - $application = htmlentities(strip_tags($application), ENT_QUOTES); + //* NOISY-DEBUG: */ printf('[%s:%d]: applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationName); + $applicationName = htmlentities(strip_tags($applicationName), ENT_QUOTES); // Secure it a little more with a reg.exp. - $application = preg_replace('/([^a-z0-9_-])+/i', '', $application); + //* NOISY-DEBUG: */ printf('[%s:%d]: applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationName); + $applicationName = preg_replace('/([^a-z0-9_-])+/i', '', $applicationName); // Construct FQPN (Full-Qualified Path Name) for ApplicationHelper class + //* NOISY-DEBUG: */ printf('[%s:%d]: applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationName); $applicationPath = sprintf( '%s%s%s', self::getConfigurationInstance()->getConfigEntry('application_base_path'), - $application, + $applicationName, DIRECTORY_SEPARATOR ); // Full path for application // Is the path there? This secures a bit the parameter (from untrusted source). + //* NOISY-DEBUG: */ printf('[%s:%d]: applicationPath=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationPath); if ((!is_dir($applicationPath)) || (!is_readable($applicationPath))) { // Not found or not readable - ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $application)); - } // END - if + ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $applicationName)); + } // Set the detected application's name and full path for later usage - self::getConfigurationInstance()->setConfigEntry('detected_full_app_path', $applicationPath); - self::getConfigurationInstance()->setConfigEntry('detected_app_name' , $application); + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting applicationPath=%s,applicationName=%s' . PHP_EOL, __METHOD__, __LINE__, $applicationPath, $applicationName); + self::$detectedApplicationPath = $applicationPath; + self::$detectedApplicationName = $applicationName; + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -714,4 +813,23 @@ final class FrameworkBootstrap { return self::$databaseInstance; } + /** + * Private getter for language instance + * + * @return $languageInstance An instance of a ManageableLanguage class + */ + public static function getLanguageInstance () { + return self::$languageInstance; + } + + /** + * Setter for language instance + * + * @param $languageInstance An instance of a ManageableLanguage class + * @return void + */ + public static function setLanguageInstance (ManageableLanguage $languageInstance) { + self::$languageInstance = $languageInstance; + } + }