From d100f068798a47a699aa723c0b4bd62b3025c1b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 11 Apr 2018 22:56:11 +0200 Subject: [PATCH] Continued: - need to initialize web output instance when request type is 'html' - but only need to shutdown (and show messages) when 'console' is set - assignApplicationData() does no longer accept $applicationInstance which makes sense as it can be obtained from GenericRegistry - also removed same parameter from factory methods - no need to invoke setApplicationInstance() for above same reason (this is called inter-mezzo pattern) - updated core to latest commit id - updated index.php from core MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- application/city/class_ApplicationHelper.php | 21 +++++++++++++------ .../html/class_CityHtmlConfirmCommand.php | 2 +- .../html/class_CityHtmlLoginAreaCommand.php | 8 +++---- .../html/class_CityHtmlLoginCommand.php | 2 +- .../html/class_CityHtmlLoginFailedCommand.php | 2 +- .../html/class_CityHtmlResendLinkCommand.php | 4 ++-- .../html/class_HtmlLogoutDoneCommand.php | 2 +- .../city_daemon/class_CityDaemonFactory.php | 4 +--- .../class_CityConsoleCommandResolver.php | 8 +++---- .../html/class_CityHtmlCommandResolver.php | 8 +++---- .../class_CityConsoleControllerResolver.php | 8 ++----- .../html/class_CityHtmlControllerResolver.php | 8 ++----- .../class_CityImageControllerResolver.php | 8 ++----- core | 2 +- index.php | 2 +- 15 files changed, 39 insertions(+), 50 deletions(-) diff --git a/application/city/class_ApplicationHelper.php b/application/city/class_ApplicationHelper.php index 5aa8b14..17bf18b 100644 --- a/application/city/class_ApplicationHelper.php +++ b/application/city/class_ApplicationHelper.php @@ -214,7 +214,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication FrameworkBootstrap::getRequestTypeFromSystem() )) ); - $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this)); + $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName)); // Get a controller instance as well $this->setControllerInstance($resolverInstance->resolveController()); @@ -225,13 +225,22 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication // And set it here $this->setLanguageInstance($languageInstance); - // Launch the test suite here + // Is html request? + if (FrameworkBootstrap::getRequestTypeFromSystem() == 'html') { + // Init web output instance + $this->initWebOutputInstance(); + } + + // Launch the application here $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); - // -------------------------- Shutdown phase -------------------------- - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...'); - $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); + // Is console request? + if (FrameworkBootstrap::getRequestTypeFromSystem() == 'console') { + // -------------------------- Shutdown phase -------------------------- + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...'); + $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); + } } /** diff --git a/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php b/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php index 81a6cab..967e687 100644 --- a/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlConfirmCommand.php @@ -76,7 +76,7 @@ class CityHtmlConfirmCommand extends BaseCommand implements Commandable { $templateInstance = $this->prepareTemplateInstance($applicationInstance); // Assign application data with template engine - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); // Assign base URL $templateInstance->assignConfigVariable('base_url'); diff --git a/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php index 4197b4d..7344cb3 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginAreaCommand.php @@ -103,7 +103,7 @@ class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable { $templateInstance->assignConfigVariable('base_url'); // Assign all the application's data with template variables - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); @@ -192,11 +192,8 @@ class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable { $this->actionName = $this->convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq; } // END - if - // Get application instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Get a resolver - $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName, $applicationInstance); + $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName); // Resolve the action $actionInstance = $actionResolver->resolveAction(); @@ -207,4 +204,5 @@ class CityHtmlLoginAreaCommand extends BaseCommand implements Commandable { // Remember this action in registry GenericRegistry::getRegistry()->addInstance('action', $actionInstance); } + } diff --git a/application/city/classes/commands/html/class_CityHtmlLoginCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginCommand.php index 5ead86c..6950759 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginCommand.php @@ -79,7 +79,7 @@ class CityHtmlLoginCommand extends BaseCommand implements Commandable, Registera $templateInstance = $this->prepareTemplateInstance($applicationInstance); // Assign application data with template engine - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); // Assign base URL $templateInstance->assignConfigVariable('base_url'); diff --git a/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php b/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php index d1c24ad..2ef1638 100644 --- a/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlLoginFailedCommand.php @@ -75,7 +75,7 @@ class CityHtmlLoginFailedCommand extends BaseCommand implements Commandable { $templateInstance = $this->prepareTemplateInstance($applicationInstance); // Assign application data with template engine - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); diff --git a/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php b/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php index c625b14..b217ff5 100644 --- a/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php +++ b/application/city/classes/commands/html/class_CityHtmlResendLinkCommand.php @@ -98,10 +98,10 @@ class CityHtmlResendLinkCommand extends BaseCommand implements Commandable { $templateInstance = $this->prepareTemplateInstance($applicationInstance); // Assign the application data with the template engine - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); // Get a mailer class - $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, $applicationInstance, 'resend_link')); + $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, 'resend_link')); // Set this mailer in our template engine $templateInstance->setMailerInstance($mailerInstance); diff --git a/application/city/classes/commands/html/class_HtmlLogoutDoneCommand.php b/application/city/classes/commands/html/class_HtmlLogoutDoneCommand.php index 90b3206..09c3e4b 100644 --- a/application/city/classes/commands/html/class_HtmlLogoutDoneCommand.php +++ b/application/city/classes/commands/html/class_HtmlLogoutDoneCommand.php @@ -76,7 +76,7 @@ class HtmlLogoutDoneCommand extends BaseCommand implements Commandable { $templateInstance = $this->prepareTemplateInstance($applicationInstance); // Assign application data - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); diff --git a/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php b/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php index c4ada48..bd84eac 100644 --- a/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php +++ b/application/city/classes/factories/city_daemon/class_CityDaemonFactory.php @@ -79,9 +79,6 @@ class CityDaemonFactory extends ObjectFactory { // Get a registry $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Set the app instance - $cityInstance->setApplicationInstance($applicationInstance); - // Add city-specific filters $cityInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); } else { @@ -92,4 +89,5 @@ class CityDaemonFactory extends ObjectFactory { // Return the instance return $cityInstance; } + } diff --git a/application/city/classes/resolver/command/console/class_CityConsoleCommandResolver.php b/application/city/classes/resolver/command/console/class_CityConsoleCommandResolver.php index 1e6fc9a..3089555 100644 --- a/application/city/classes/resolver/command/console/class_CityConsoleCommandResolver.php +++ b/application/city/classes/resolver/command/console/class_CityConsoleCommandResolver.php @@ -3,7 +3,6 @@ namespace Org\Mxchange\City\Resolver\Command; // Import framework stuff -use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Resolver\Command\BaseCommandResolver; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -47,12 +46,11 @@ class CityConsoleCommandResolver extends BaseCommandResolver implements CommandR * Creates an instance of a CityConsole command resolver with a given default command * * @param $commandName The default command we shall execute - * @param $applicationInstance An instance of a manageable application helper class * @return $resolverInstance The prepared command resolver instance * @throws EmptyVariableException Thrown if default command is not set * @throws InvalidCommandException Thrown if default command is invalid */ - public static final function createCityConsoleCommandResolver ($commandName, ManageableApplication $applicationInstance) { + public static final function createCityConsoleCommandResolver ($commandName) { // Create the new instance $resolverInstance = new CityConsoleCommandResolver(); @@ -65,11 +63,11 @@ class CityConsoleCommandResolver extends BaseCommandResolver implements CommandR throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } - // Set namespace and application instance + // Set namespace $resolverInstance->setNamespace('Org\Mxchange\City\Command'); - $resolverInstance->setApplicationInstance($applicationInstance); // Return the prepared instance return $resolverInstance; } + } diff --git a/application/city/classes/resolver/command/html/class_CityHtmlCommandResolver.php b/application/city/classes/resolver/command/html/class_CityHtmlCommandResolver.php index 90ac6ff..4b7cac4 100644 --- a/application/city/classes/resolver/command/html/class_CityHtmlCommandResolver.php +++ b/application/city/classes/resolver/command/html/class_CityHtmlCommandResolver.php @@ -3,7 +3,6 @@ namespace Org\Mxchange\City\Resolver\Command; // Import framework stuff -use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Resolver\Command\BaseCommandResolver; use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver; @@ -47,12 +46,11 @@ class CityHtmlCommandResolver extends BaseCommandResolver implements CommandReso * Creates an instance of a CityHtml command resolver with a given default command * * @param $commandName The default command we shall execute - * @param $applicationInstance An instance of a manageable application helper class * @return $resolverInstance The prepared command resolver instance * @throws EmptyVariableException Thrown if default command is not set * @throws InvalidCommandException Thrown if default command is invalid */ - public static final function createCityHtmlCommandResolver ($commandName, ManageableApplication $applicationInstance) { + public static final function createCityHtmlCommandResolver ($commandName) { // Create the new instance $resolverInstance = new CityHtmlCommandResolver(); @@ -65,11 +63,11 @@ class CityHtmlCommandResolver extends BaseCommandResolver implements CommandReso throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } - // Set namespace and application instance + // Set namespace $resolverInstance->setNamespace('Org\Mxchange\City\Command'); - $resolverInstance->setApplicationInstance($applicationInstance); // Return the prepared instance return $resolverInstance; } + } diff --git a/application/city/classes/resolver/controller/console/class_CityConsoleControllerResolver.php b/application/city/classes/resolver/controller/console/class_CityConsoleControllerResolver.php index 1fc1fba..dac203a 100644 --- a/application/city/classes/resolver/controller/console/class_CityConsoleControllerResolver.php +++ b/application/city/classes/resolver/controller/console/class_CityConsoleControllerResolver.php @@ -3,7 +3,6 @@ namespace Org\Mxchange\City\Resolver\Controller; // Import framework stuff -use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Resolver\Controller\BaseControllerResolver; use Org\Mxchange\CoreFramework\Resolver\Controller\ControllerResolver; @@ -47,12 +46,11 @@ class CityConsoleControllerResolver extends BaseControllerResolver implements Co * Creates an instance of a resolver class with a given controller * * @param $controllerName The controller we shall resolve - * @param $applicationInstance An instance of a manageable application helper class * @return $resolverInstance The prepared controller resolver instance * @throws EmptyVariableException Thrown if default controller is not set * @throws InvalidControllerException Thrown if default controller is invalid */ - public static final function createCityConsoleControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + public static final function createCityConsoleControllerResolver ($controllerName) { // Create the new instance $resolverInstance = new CityConsoleControllerResolver(); @@ -65,9 +63,6 @@ class CityConsoleControllerResolver extends BaseControllerResolver implements Co throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); } - // Set the application instance - $resolverInstance->setApplicationInstance($applicationInstance); - // Set namespace and controller name $resolverInstance->setNamespace('Org\Mxchange\City\Controller'); $resolverInstance->setControllerName($controllerName); @@ -75,4 +70,5 @@ class CityConsoleControllerResolver extends BaseControllerResolver implements Co // Return the prepared instance return $resolverInstance; } + } diff --git a/application/city/classes/resolver/controller/html/class_CityHtmlControllerResolver.php b/application/city/classes/resolver/controller/html/class_CityHtmlControllerResolver.php index f7bcba4..c700165 100644 --- a/application/city/classes/resolver/controller/html/class_CityHtmlControllerResolver.php +++ b/application/city/classes/resolver/controller/html/class_CityHtmlControllerResolver.php @@ -3,7 +3,6 @@ namespace Org\Mxchange\City\Resolver\Controller; // Import framework stuff -use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Resolver\Controller\BaseControllerResolver; use Org\Mxchange\CoreFramework\Resolver\Controller\ControllerResolver; @@ -47,12 +46,11 @@ class CityHtmlControllerResolver extends BaseControllerResolver implements Contr * Creates an instance of a resolver class with a given controller * * @param $controllerName The controller we shall resolve - * @param $applicationInstance An instance of a manageable application helper class * @return $resolverInstance The prepared controller resolver instance * @throws EmptyVariableException Thrown if default controller is not set * @throws InvalidControllerException Thrown if default controller is invalid */ - public static final function createCityHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + public static final function createCityHtmlControllerResolver ($controllerName) { // Create the new instance $resolverInstance = new CityHtmlControllerResolver(); @@ -65,9 +63,6 @@ class CityHtmlControllerResolver extends BaseControllerResolver implements Contr throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); } - // Set the application instance - $resolverInstance->setApplicationInstance($applicationInstance); - // Set namespace and controller name $resolverInstance->setNamespace('Org\Mxchange\City\Controller'); $resolverInstance->setControllerName($controllerName); @@ -75,4 +70,5 @@ class CityHtmlControllerResolver extends BaseControllerResolver implements Contr // Return the prepared instance return $resolverInstance; } + } diff --git a/application/city/classes/resolver/controller/image/class_CityImageControllerResolver.php b/application/city/classes/resolver/controller/image/class_CityImageControllerResolver.php index 831d9ad..0c25ef1 100644 --- a/application/city/classes/resolver/controller/image/class_CityImageControllerResolver.php +++ b/application/city/classes/resolver/controller/image/class_CityImageControllerResolver.php @@ -3,7 +3,6 @@ namespace Org\Mxchange\City\Resolver\Controller; // Import framework stuff -use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Resolver\Controller\BaseControllerResolver; use Org\Mxchange\CoreFramework\Resolver\Controller\ControllerResolver; @@ -47,12 +46,11 @@ class CityImageControllerResolver extends BaseControllerResolver implements Cont * Creates an instance of a resolver class with a given controller * * @param $controllerName The controller we shall resolve - * @param $applicationInstance An instance of a manageable application helper class * @return $resolverInstance The prepared controller resolver instance * @throws EmptyVariableException Thrown if default controller is not set * @throws InvalidControllerException Thrown if default controller is invalid */ - public static final function createCityImageControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + public static final function createCityImageControllerResolver ($controllerName) { // Create the new instance $resolverInstance = new CityImageControllerResolver(); @@ -65,9 +63,6 @@ class CityImageControllerResolver extends BaseControllerResolver implements Cont throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); } - // Set the application instance - $resolverInstance->setApplicationInstance($applicationInstance); - // Set namespace and controller name $resolverInstance->setNamespace('Org\Mxchange\City\Controller'); $resolverInstance->setControllerName($controllerName); @@ -75,4 +70,5 @@ class CityImageControllerResolver extends BaseControllerResolver implements Cont // Return the prepared instance return $resolverInstance; } + } diff --git a/core b/core index e137daa..2b4f4b8 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e137daa3a06f4b9e3767db913854c609383e8533 +Subproject commit 2b4f4b88ec5f9d385110e800494c680e164b5a36 diff --git a/index.php b/index.php index 1e7f1d4..e3c5da8 100644 --- a/index.php +++ b/index.php @@ -137,7 +137,7 @@ final class ApplicationEntryPoint { $applicationInstance = ApplicationHelper::getSelfInstance(); // Assign application data - $templateInstance->assignApplicationData($applicationInstance); + $templateInstance->assignApplicationData(); } // END - if // We only try this -- 2.39.5