From 108f2391252a823f0e26b2c3e9e18843ce224ecd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 6 Dec 2020 10:32:52 +0100 Subject: [PATCH] Continued: - updated index.php - PHP_Invoker is now with a namespace, so no need for disabling strict naming-convention check - removed some old END - * - renamed configuration entries 'detect_*' to '__detect_*' as they are dummies - maybe later get rid of them as the configuration class seem to be "abused" here a bit - converted old array() to "new" [] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- application/tests/exceptions.php | 4 +- .../bootstrap/class_FrameworkBootstrap.php | 52 +++++++++---------- framework/loader/class_ClassLoader.php | 6 +-- index.php | 45 +++++++--------- .../class_FrameworkBootstrapTest.php | 8 --- .../config/FrameworkConfigurationTest.php | 8 --- 6 files changed, 51 insertions(+), 72 deletions(-) diff --git a/application/tests/exceptions.php b/application/tests/exceptions.php index 66121d2b..6e1852eb 100644 --- a/application/tests/exceptions.php +++ b/application/tests/exceptions.php @@ -114,7 +114,7 @@ function tests_error_handler ($errno, $errstr, $errfile, $errline, array $errcon // Throw an exception here throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR); -} // END - function +} // Assertion handler function tests_assert_handler (string $file, int $line, $code) { @@ -135,7 +135,7 @@ function tests_assert_handler (string $file, int $line, $code) { // Throw an exception here throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED); -} // END - function +} // Set error handler //set_error_handler('tests_error_handler'); diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index 9f376df5..5d9aa027 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -84,7 +84,7 @@ final class FrameworkBootstrap { * 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) @@ -103,7 +103,7 @@ final class FrameworkBootstrap { 'init' => 'deprecated', // Application starter (deprecated) 'starter' => 'deprecated', - ); + ]; /** * Private constructor, no instance is needed from this class as only @@ -123,7 +123,7 @@ final class FrameworkBootstrap { if (is_null(self::$configurationInstance)) { // Init new instance self::$configurationInstance = new FrameworkConfiguration(); - } // END - if + } // Return it return self::$configurationInstance; @@ -142,7 +142,7 @@ final class FrameworkBootstrap { if (isset($_SERVER['HTTP_HOST'])) { // Then it is a HTML response/request. $requestType = 'html'; - } // END - if + } // Return it return $requestType; @@ -174,8 +174,8 @@ final class FrameworkBootstrap { // Abort lookup as it has been found in open_basedir break; - } // END - if - } // END - foreach + } + } } else { // If open_basedir is not set, all is allowed $isReachable = true; @@ -226,7 +226,7 @@ final class FrameworkBootstrap { if (!self::isReadableFile($fileInstance)) { // Abort here throw new InvalidArgumentException(sprintf('Cannot find fileInstance.pathname=%s.', $fileInstance->getPathname())); - } // END - if + } // Load it require_once $fileInstance->getPathname(); @@ -292,9 +292,9 @@ 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'); + // 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 @@ -323,11 +323,11 @@ final class FrameworkBootstrap { // Skip loading deprecated file continue; - } // END - if + } // Load it self::loadInclude($fileInstance); - } // END - foreach + } // Scan for application's classes, exceptions and interfaces ClassLoader::scanApplicationClasses(); @@ -340,8 +340,8 @@ 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'); + // Configuration entry '__detected_app_name' must be set, get it here + $application = self::getConfigurationInstance()->getConfigEntry('__detected_app_name'); // Is there an application helper instance? $applicationInstance = call_user_func_array( @@ -377,7 +377,7 @@ final class FrameworkBootstrap { // Call method call_user_func(array($applicationInstance, $methodName)); - } // END - foreach + } } /** @@ -393,7 +393,7 @@ final class FrameworkBootstrap { 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'); @@ -430,7 +430,7 @@ final class FrameworkBootstrap { * 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 self::$serverAddress = $serverIp; @@ -438,7 +438,7 @@ final class FrameworkBootstrap { // Run auto-detecting through console tools lib self::$serverAddress = ConsoleTools::acquireSelfIpAddress(); } - } // END - if + } // Return it return self::$serverAddress; @@ -508,7 +508,7 @@ final class FrameworkBootstrap { 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()); @@ -530,7 +530,7 @@ final class FrameworkBootstrap { if (isset($_SERVER['SERVER_NAME'])) { // Detect the full domain $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES); - } // END - if + } // Return it return $fullDomain; @@ -550,7 +550,7 @@ final class FrameworkBootstrap { 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 return $scriptPath; @@ -601,7 +601,7 @@ 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', StringUtils::convertToClassName($request)); @@ -625,7 +625,7 @@ 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'); @@ -649,11 +649,11 @@ final class FrameworkBootstrap { if ((!is_dir($applicationPath)) || (!is_readable($applicationPath))) { // Not found or not readable ApplicationEntryPoint::exitApplication(sprintf('Application "%s" not found.', $application)); - } // END - if + } // 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); + self::getConfigurationInstance()->setConfigEntry('__detected_full_app_path', $applicationPath); + self::getConfigurationInstance()->setConfigEntry('__detected_app_name' , $application); } /** diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index 72d25add..4c1ce581 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -272,7 +272,7 @@ class ClassLoader { '%s%s%s%s%s', $configInstance->getConfigEntry('application_base_path'), DIRECTORY_SEPARATOR, - $configInstance->getConfigEntry('detected_app_name'), + $configInstance->getConfigEntry('__detected_app_name'), DIRECTORY_SEPARATOR, $shortPath )); @@ -505,8 +505,8 @@ class ClassLoader { // Construct the FQFN for the cache if (!FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('developer_mode_enabled')) { // Init cache instances - $this->listCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'list-' . $this->configInstance->getConfigEntry('detected_app_name') . '.cache'); - $this->classCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'class-' . $this->configInstance->getConfigEntry('detected_app_name') . '.cache'); + $this->listCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'list-' . $this->configInstance->getConfigEntry('__detected_app_name') . '.cache'); + $this->classCacheFile = new SplFileInfo($this->configInstance->getConfigEntry('local_database_path') . 'class-' . $this->configInstance->getConfigEntry('__detected_app_name') . '.cache'); } // Set suffix and prefix from configuration diff --git a/index.php b/index.php index 818fb738..bc2faf43 100644 --- a/index.php +++ b/index.php @@ -57,12 +57,12 @@ final class ApplicationEntryPoint { * @return void * @todo This method is old code and needs heavy rewrite and should be moved to ApplicationHelper */ - public static final function exitApplication ($message = '', $code = false, $extraData = '', $silentMode = false) { + public static final function exitApplication (string $message = '', int $code = -1, string $extraData = '', bool $silentMode = false) { // Is this method already called? if (isset($GLOBALS['app_die_called'])) { // Then output the text directly exit($message); - } // END - if + } // This method shall not be called twice $GLOBALS['app_die_called'] = true; @@ -71,7 +71,7 @@ final class ApplicationEntryPoint { if (empty($message)) { // No message provided $message = 'No message provided.'; - } // END - if + } // Get config instance $configInstance = FrameworkBootstrap::getConfigurationInstance(); @@ -79,8 +79,8 @@ final class ApplicationEntryPoint { // Do we have debug installation? if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) { // Abort here - exit(); - } // END - if + exit; + } // Get some instances $tpl = $configInstance->getConfigEntry('html_template_class'); @@ -105,19 +105,18 @@ final class ApplicationEntryPoint { } // Get and prepare backtrace for output - $backtraceArray = debug_backtrace(); $backtrace = ''; - foreach ($backtraceArray as $key => $trace) { + foreach (debug_backtrace() as $key => $trace) { // Set missing array elements if (!isset($trace['file'])) { $trace['file'] = __FILE__; - } // END - if + } if (!isset($trace['line'])) { $trace['line'] = __LINE__; - } // END - if + } if (!isset($trace['args'])) { $trace['args'] = array(); - } // END - if + } // Add the traceback path to the final output $backtrace .= sprintf('%s:%d, %s(%d)
' . PHP_EOL, @@ -126,7 +125,7 @@ final class ApplicationEntryPoint { $trace['function'], count($trace['args']) ); - } // END - foreach + } // Init application instance $applicationInstance = NULL; @@ -138,7 +137,7 @@ final class ApplicationEntryPoint { // Assign application data $templateInstance->assignApplicationData(); - } // END - if + } // We only try this try { @@ -171,10 +170,10 @@ final class ApplicationEntryPoint { } // Good bye... - exit(); + exit; } else { // Output message and die - exit(sprintf('[Main:] Emergency exit reached: %s', + die(sprintf('[Main:] Emergency exit reached: %s', $message )); } @@ -196,14 +195,12 @@ final class ApplicationEntryPoint { // Create full path for testing $realPath = realpath($possiblePath); - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath); - // Is it false? + //* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath); if ($realPath === false) { // Then, not found. continue; - } // END - if + } // Append framework path $frameworkPath = sprintf('%s%sframework%s', $realPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); @@ -211,25 +208,23 @@ final class ApplicationEntryPoint { // First create full-qualified file name (FQFN) to framework/config-global.php $configFile = $frameworkPath . 'config-global.php'; - // Debug message - //* NOISY-DEBUG: */ printf('[%s:%d]: configFile=%s' . PHP_EOL, __METHOD__, __LINE__, $configFile); - // Is it readable? + //* NOISY-DEBUG: */ printf('[%s:%d]: configFile=%s' . PHP_EOL, __METHOD__, __LINE__, $configFile); if (is_readable($configFile)) { // Found one self::$frameworkPath = $frameworkPath; // 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::$frameworkPath; diff --git a/tests/framework/bootstrap/class_FrameworkBootstrapTest.php b/tests/framework/bootstrap/class_FrameworkBootstrapTest.php index 7b900fd2..ff22b9a9 100644 --- a/tests/framework/bootstrap/class_FrameworkBootstrapTest.php +++ b/tests/framework/bootstrap/class_FrameworkBootstrapTest.php @@ -1,11 +1,9 @@