]> git.mxchange.org Git - city.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 18 Feb 2023 23:54:12 +0000 (00:54 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 19 Feb 2023 00:17:51 +0000 (01:17 +0100)
- exit; means normal exit which isn't the case here
- updated 'core' framework

application/city/exceptions.php
core
index.php

index f548876ee45d3908e22818eaa9852a24f03959b3..5128f0895ad856dea63c77bc91b3608272bf1a92 100644 (file)
@@ -10,7 +10,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
+ * @copyright  Copyright (c) 2015 - 2023 City Developer Team
  * @license            GNU GPL 3.0 or any newer version
  *
  * This program is free software: you can redistribute it and/or modify
@@ -34,6 +34,9 @@ function city_exception_handler ($exceptionInstance) {
                // Init variable
                $backTrace = '';
 
+               // Generate exception code
+               $exceptionCode = ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode()));
+
                // Get all call levels from backtrace
                foreach ($exceptionInstance->getTrace() as $idx => $traceArray) {
                        // Init argument string
@@ -84,7 +87,7 @@ Backtrace:
 --------------------------------------------------------------------------------\n",
                        trim(html_entity_decode(strip_tags(get_class($exceptionInstance)))),
                        trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
-                       ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode())),
+                       $exceptionCode,
                        $exceptionInstance->getFile(),
                        $exceptionInstance->getLine(),
                        trim($backTrace)
@@ -92,23 +95,28 @@ Backtrace:
 
                // Output the message
                print($message);
+
+               // Exit with code
+               exit(hexdec($exceptionCode));
        } elseif (is_object($exceptionInstance)) {
                // Output more details
                printf('exceptionInstance=%s', print_r($exceptionInstance, true));
+               exit(255);
        } else {
                /*
                 * Invalid exception instance detected! Do *only* throw exceptions that
                 * extends our own exception 'FrameworkException' to get such nice
                 * outputs like above.
                 */
-               printf('exceptionInstance[]=%s is invalid! Please inform the core developer team.' . PHP_EOL, gettype($exceptionInstance));
+               printf('exceptionInstance[]=%s is invalid! Please inform the city developer team.' . PHP_EOL, gettype($exceptionInstance));
+               exit(255);
        }
 }
 
 // Error handler
-function city_error_handler ($errno, $errstr, $errfile, $errline, array $errcontext) {
+function city_error_handler (int $errno, string $errstr, string $errfile, int $errline, array $errcontext) {
        // Construct the message
-       $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s',
+       $message = sprintf('File: %s, Line: %d, Code: %d, Message: %s',
                basename($errfile),
                $errline,
                $errno,
@@ -122,7 +130,7 @@ function city_error_handler ($errno, $errstr, $errfile, $errline, array $errcont
 // Assertion handler
 function city_assert_handler (string $file, int $line, int $code) {
        // Empty code?
-       if ($code === '') {
+       if (empty($code)) {
                $code = '<em>Unknown</em>';
        }
 
diff --git a/core b/core
index 027c5659e968546a21be37e70d700c7e14cba993..f861d6bc00f8a3ecf6b057f2aa93129572643896 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 027c5659e968546a21be37e70d700c7e14cba993
+Subproject commit f861d6bc00f8a3ecf6b057f2aa93129572643896
index 46f5db5e3db33873e9aabba507ef3140aeb84367..94177e3062c449faaa117332f0d0fac89dad4038 100644 (file)
--- a/index.php
+++ b/index.php
@@ -8,6 +8,7 @@ use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
 use Org\Mxchange\CoreFramework\Localization\LanguageSystem;
+use Org\Mxchange\CoreFramework\Localization\ManageableLanguage;
 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
 use Org\Mxchange\CoreFramework\Generic\FrameworkException;
 
@@ -24,7 +25,7 @@ use \Exception;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -61,7 +62,8 @@ final class ApplicationEntryPoint {
                // Is this method already called?
                if (isset($GLOBALS['app_die_called'])) {
                        // Then output the text directly
-                       exit($message);
+                       print $message . PHP_EOL;
+                       exit(255);
                }
 
                // This method shall not be called twice
@@ -79,11 +81,11 @@ final class ApplicationEntryPoint {
                // Do we have debug installation?
                if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) {
                        // Abort here
-                       exit;
+                       exit(255);
                }
 
                // Get some instances
-               $tpl = $configInstance->getConfigEntry('html_template_class');
+               $templateClassName = $configInstance->getConfigEntry('html_template_class');
                $languageInstance = LanguageSystem::getSelfInstance();
 
                // Initialize template instance here to avoid warnings in IDE
@@ -93,11 +95,11 @@ final class ApplicationEntryPoint {
                $responseInstance = FrameworkBootstrap::getResponseInstance();
 
                // Is the template engine loaded?
-               if ((class_exists($tpl)) && (is_object($languageInstance))) {
+               if ((class_exists($templateClassName)) && ($languageInstance instanceof ManageableLanguage)) {
                        // Use the template engine for putting out (nicer look) the message
                        try {
                                // Get the template instance from our object factory
-                               $templateInstance = ObjectFactory::createObjectByName($tpl);
+                               $templateInstance = ObjectFactory::createObjectByName($templateClassName);
                        } catch (FrameworkException $e) {
                                exit(sprintf('[Main:] Could not initialize template engine for reason: <span class="exception_reason">%s</span>',
                                        $e->getMessage()
@@ -130,7 +132,13 @@ final class ApplicationEntryPoint {
                        // Init application instance
                        $applicationInstance = NULL;
 
-                       // Is the class there?
+                       /*
+                        * The following class may NOT be loaded at all times. For example,
+                        * it might be the (rare) case that an error has happened BEFORE
+                        * that class had been loaded and cannot be loaded or else an
+                        * infinte loop in invoking this method will take place resulting in
+                        * a stack-overflow error.
+                        */
                        if (class_exists('Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper')) {
                                // Get application instance
                                $applicationInstance = ApplicationHelper::getSelfInstance();
@@ -166,16 +174,16 @@ final class ApplicationEntryPoint {
                                $responseInstance->flushBuffer();
                        } catch (FileNotFoundException $e) {
                                // Even the template 'emergency_exit' wasn't found so output both message
-                               exit($message . ', exception: ' . $e->getMessage());
+                               print ($message . ', exception: ' . $e->getMessage() . PHP_EOL);
+                               exit($e->getCode());
                        }
 
                        // Good bye...
-                       exit;
+                       exit(255);
                } else {
                        // Output message and die
-                       die(sprintf('[Main:] Emergency exit reached: <span class="emergency_span">%s</span>',
-                               $message
-                       ));
+                       printf('[Main:] Emergency exit reached: <span class="emergency_span">%s</span>', $message);
+                       exit(255);
                }
        }