From: Roland Häder Date: Fri, 24 Feb 2023 06:00:09 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=54b38df111fa5a40578094b494c186b028301f4c;p=core.git Continued: - added more debug lines - commented some out again --- diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index d3c3c02d..65b017a9 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -228,10 +228,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) @@ -243,6 +241,7 @@ final class FrameworkBootstrap { ); // Return status + //* NOISY-DEBUG: */ printf('[%s:%d]: isReadable=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, intval($isReadable)); return $isReadable; } @@ -313,6 +312,7 @@ 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(); /* @@ -329,6 +329,9 @@ final class FrameworkBootstrap { * found, continue below with next step. */ self::validateApplicationParameter(); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -343,7 +346,7 @@ final class FrameworkBootstrap { * Now check and load all files, found deprecated files will throw a * warning at the user. */ - /* NOISY-DEBUG: */ printf('[%s:%d]: self::configAppIncludes()=%d' . PHP_EOL, __METHOD__, __LINE__, count(self::$configAppIncludes)); + //* 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 //* NOISY-DEBUG: */ printf('[%s:%d]: fileName=%s,status=%s' . PHP_EOL, __METHOD__, __LINE__, $fileName, $status); @@ -381,6 +384,9 @@ final class FrameworkBootstrap { // Scan for application's classes, exceptions and interfaces ClassLoader::scanApplicationClasses(); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -435,12 +441,15 @@ final class FrameworkBootstrap { * 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.'); @@ -453,7 +462,11 @@ final class FrameworkBootstrap { $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $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__); } /** @@ -465,16 +478,20 @@ 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 @@ -484,14 +501,17 @@ final class FrameworkBootstrap { } // 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(); } } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: self::serverAddress=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$serverAddress); return self::$serverAddress; } @@ -504,6 +524,7 @@ final class FrameworkBootstrap { */ 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('Parameter "timezone" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT); @@ -519,6 +540,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; } @@ -529,6 +551,7 @@ final class FrameworkBootstrap { * @todo Test more fields */ public static function isHttpSecured () { + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); return ( ( ( @@ -553,6 +576,7 @@ 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? @@ -565,6 +589,7 @@ final class FrameworkBootstrap { $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; } @@ -575,6 +600,7 @@ 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? @@ -584,6 +610,7 @@ final class FrameworkBootstrap { } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: fullDomain=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $fullDomain); return $fullDomain; } @@ -595,6 +622,7 @@ 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? @@ -604,6 +632,7 @@ final class FrameworkBootstrap { } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: scriptPath=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $scriptPath); return $scriptPath; } @@ -621,6 +650,7 @@ final class FrameworkBootstrap { */ private static function scanFrameworkClasses () { // 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 @@ -628,6 +658,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__); } /** @@ -638,13 +671,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 + //* 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? @@ -655,10 +691,15 @@ final class FrameworkBootstrap { } // ... and a new response object + //* 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__); } /** @@ -668,6 +709,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 @@ -681,12 +723,15 @@ final class FrameworkBootstrap { $applicationName = self::getRequestInstance()->getRequestElement('app'); // Secure it, by keeping out tags + //* 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. + //* 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'), @@ -696,14 +741,19 @@ final class FrameworkBootstrap { // 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.', $applicationName)); } // Set the detected application's name and full path for later usage + //* 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__); } /** diff --git a/index.php b/index.php index 94177e30..37fa2612 100644 --- a/index.php +++ b/index.php @@ -60,6 +60,7 @@ final class ApplicationEntryPoint { */ public static final function exitApplication (string $message = '', int $code = -1, string $extraData = '', bool $silentMode = false) { // Is this method already called? + //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,code=%d,extraData=%s,silentMode=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, $code, $extraData, intval($silentMode)); if (isset($GLOBALS['app_die_called'])) { // Then output the text directly print $message . PHP_EOL; @@ -81,6 +82,7 @@ final class ApplicationEntryPoint { // Do we have debug installation? if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) { // Abort here + //* NOISY-DEBUG: */ printf('[%s:%d]: product_install_mode=%d,silentMode=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $configInstance->getConfigEntry('product_install_mode'), intval($silentMode)); exit(255); } @@ -185,6 +187,9 @@ final class ApplicationEntryPoint { printf('[Main:] Emergency exit reached: %s', $message); exit(255); } + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } /** @@ -197,16 +202,19 @@ final class ApplicationEntryPoint { */ public static final function detectFrameworkPath () { // Is it not set? + //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath); if (empty(self::$frameworkPath)) { // Auto-detect core path (first application-common) - foreach (array('core', __DIR__, '/usr/local/share/php/core', '/usr/share/php/core') as $possiblePath) { + foreach (['core', self::getRootPath(), '/usr/local/share/php/core', '/usr/share/php/core'] as $possiblePath) { // Create full path for testing + //* NOISY-DEBUG: */ printf('[%s:%d]: possiblePath=%s' . PHP_EOL, __METHOD__, __LINE__, $possiblePath); $realPath = realpath($possiblePath); // Is it false? //* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath); if ($realPath === false) { // Then, not found. + //* NOISY-DEBUG: */ printf('[%s:%d]: possiblePath=%s was not found. - SKIPPED!' . PHP_EOL, __METHOD__, __LINE__, $possiblePath); continue; } @@ -214,6 +222,7 @@ final class ApplicationEntryPoint { $frameworkPath = sprintf('%s%sframework%s', $realPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); // First create full-qualified file name (FQFN) to framework/config-global.php + //* NOISY-DEBUG: */ printf('[%s:%d]: frameworkPath=%s' . PHP_EOL, __METHOD__, __LINE__, $frameworkPath); $configFile = $frameworkPath . 'config-global.php'; // Is it readable? @@ -223,11 +232,13 @@ final class ApplicationEntryPoint { self::$frameworkPath = $frameworkPath; // Abort here + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::frameworkPath=%s - BREAK!' . PHP_EOL, __METHOD__, __LINE__, $frameworkPath); break; } } // Able to find? + //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - Checking ...' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath); if (!is_dir(self::$frameworkPath)) { // Is no directory throw new Exception('Cannot find framework.'); @@ -235,6 +246,7 @@ final class ApplicationEntryPoint { } // Return it + //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath); return self::$frameworkPath; } @@ -258,6 +270,7 @@ final class ApplicationEntryPoint { */ public static final function main () { // Load bootstrap file + //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__); require sprintf('%sbootstrap%sbootstrap.inc.php', self::detectFrameworkPath(), DIRECTORY_SEPARATOR); /* @@ -274,13 +287,14 @@ final class ApplicationEntryPoint { * register the application instance in registry. */ FrameworkBootstrap::startApplication(); + + // Trace message + //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__); } } // Log all exceptions (only debug! This option can create large error logs) //define('LOG_EXCEPTIONS', true); -//xdebug_start_trace(); - // Call above main() method ApplicationEntryPoint::main();