From: Roland Häder Date: Sun, 6 Dec 2020 07:52:03 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8a0e2f9c53bbdd4f85ccdbdaee324ee7bfb7b862;p=city.git Continued: - Application instance in generic registry was a little of an overdoze when there is ApplicationHelper::getSelfInstance() around, this means lesser method invocations and a bit smaller footprint (one registry entry lesser) - updated core framework Signed-off-by: Roland Häder --- diff --git a/application/city/classes/city_daemon/class_BaseCityDaemon.php b/application/city/classes/city_daemon/class_BaseCityDaemon.php index 11c6b33..e45a0f7 100644 --- a/application/city/classes/city_daemon/class_BaseCityDaemon.php +++ b/application/city/classes/city_daemon/class_BaseCityDaemon.php @@ -16,6 +16,7 @@ use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend; use Org\Mxchange\CoreFramework\Database\Updateable; use Org\Mxchange\CoreFramework\Factory\Database\Frontend\DatabaseFrontendFactory; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry;; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Response\Responseable; @@ -109,7 +110,7 @@ abstract class BaseCityDaemon extends BaseCitySystem implements Updateable, Adda */ public function outputConsoleTeaser () { // Get the app instance (for shortening our code) - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Output all lines self::createDebugInstance(__CLASS__)->debugOutput(' '); diff --git a/application/city/classes/city_daemon/default/class_SimulationDefaultCityDaemon.php b/application/city/classes/city_daemon/default/class_SimulationDefaultCityDaemon.php index f58e327..5eba097 100644 --- a/application/city/classes/city_daemon/default/class_SimulationDefaultCityDaemon.php +++ b/application/city/classes/city_daemon/default/class_SimulationDefaultCityDaemon.php @@ -9,6 +9,7 @@ use Org\Mxchange\City\Helper\CityHelper; // Import framework stuff use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Handler\Task\HandleableTask; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Request\Requestable; @@ -77,7 +78,7 @@ class SimulationDefaultCityDaemon extends BaseCityDaemon implements CityHelper, */ public function addExtraCityFilters () { // Get the application instance from registry - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Get the controller from the application $controllerInstance = $applicationInstance->getControllerInstance(); diff --git a/application/city/classes/commands/console/class_CityConsoleDaemonCommand.php b/application/city/classes/commands/console/class_CityConsoleDaemonCommand.php index f523e58..b985a4a 100644 --- a/application/city/classes/commands/console/class_CityConsoleDaemonCommand.php +++ b/application/city/classes/commands/console/class_CityConsoleDaemonCommand.php @@ -10,6 +10,7 @@ use Org\Mxchange\CoreFramework\Command\BaseCommand; use Org\Mxchange\CoreFramework\Command\Commandable; use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -75,7 +76,7 @@ class CityConsoleDaemonCommand extends BaseCommand implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get a registry and the application instance from it - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); /* * ----------------------- Bootstrapping phase ------------------------ diff --git a/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php b/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php index 50b0566..ad4a9ad 100644 --- a/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php @@ -10,6 +10,7 @@ use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Generic\NullPointerException; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -74,7 +75,7 @@ class CityHtmlConfirmCommand extends BaseCommand implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get the application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($applicationInstance); diff --git a/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php index 70ae9d4..335a7af 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php @@ -6,6 +6,7 @@ namespace Org\Mxchange\City\Command; use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -96,7 +97,7 @@ class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable { } // END - if // Get the application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($applicationInstance); diff --git a/application/city/classes/commands/html/class_CityHtmlLoginCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginCommand.php index 7446134..194ad83 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginCommand.php @@ -8,6 +8,7 @@ use Org\Mxchange\CoreFramework\Command\BaseCommand; use Org\Mxchange\CoreFramework\Command\Commandable; use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry;; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Request\Requestable; @@ -76,7 +77,7 @@ class CityHtmlLoginCommand extends BaseCommand implements Commandable, Registera GenericRegistry::getRegistry()->addInstance('extra', $this); // Get the application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($applicationInstance); diff --git a/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php index ce21d18..aad1e16 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php @@ -8,6 +8,7 @@ use Org\Mxchange\CoreFramework\Command\BaseCommand; use Org\Mxchange\CoreFramework\Command\Commandable; use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry;; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -72,7 +73,7 @@ class CityHtmlLoginFailedCommand extends BaseCommand implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get the application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($applicationInstance); diff --git a/application/city/classes/commands/html/class_CityHtmlLogoutDoneCommand.php b/application/city/classes/commands/html/class_CityHtmlLogoutDoneCommand.php index d9dac7a..598b7a1 100644 --- a/application/city/classes/commands/html/class_CityHtmlLogoutDoneCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLogoutDoneCommand.php @@ -8,6 +8,7 @@ use Org\Mxchange\CoreFramework\Command\BaseCommand; use Org\Mxchange\CoreFramework\Command\Commandable; use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry;; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -72,7 +73,7 @@ class CityHtmlLogoutDoneCommand extends BaseCommand implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get the application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Prepare a template instance $templateInstance = $this->prepareTemplateInstance($applicationInstance); diff --git a/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php b/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php index 5107e75..5e52149 100644 --- a/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php @@ -9,6 +9,7 @@ use Org\Mxchange\CoreFramework\Command\Commandable; use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -76,7 +77,7 @@ class CityHtmlResendLinkCommand extends BaseCommand implements Commandable { $userInstance = GenericRegistry::getRegistry()->getInstance('user'); // Get an application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Get a RNG instance (Random Number Generator) $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); diff --git a/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php b/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php index a44ae87..3bb123d 100644 --- a/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php +++ b/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php @@ -5,6 +5,7 @@ namespace Org\Mxchange\City\Daemon\Factory; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; +use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\Response\Responseable; @@ -78,7 +79,7 @@ class CityDaemonFactory extends ObjectFactory { $cityInstance = ObjectFactory::createObjectByConfiguredName($configEntry, array($requestInstance)); // Get a registry - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); + $applicationInstance = ApplicationHelper::getSelfInstance(); // Add city-specific filters $cityInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); diff --git a/core b/core index 196ab0f..6e91754 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 196ab0fc031d6987c87e8c5d257c39f664ec9151 +Subproject commit 6e91754d589773df8bd3746008dd782133a48674 diff --git a/index.php b/index.php index 818fb73..bc2faf4 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;