From b470fb8107e5029819c345f23a961fbd8085af7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 7 Nov 2020 20:51:28 +0100 Subject: [PATCH] Continued: - rewrote template engine initialization: + BaseFrameworkSystem->initTemplateEngine() was monolithic and can be done in BaseCommand class + the template engine's type is determined by system (console, html, image, ...) for the command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../bootstrap/class_FrameworkBootstrap.php | 3 - framework/config-global.php | 3 + .../classes/class_BaseFrameworkSystem.php | 55 ------------------- .../classes/commands/class_BaseCommand.php | 49 ++++++++++------- .../html/class_HtmlConfirmCommand.php | 35 ++++++------ .../commands/html/class_HtmlHomeCommand.php | 30 +++++----- .../html/class_HtmlLoginAreaCommand.php | 41 +++++++------- .../commands/html/class_HtmlLoginCommand.php | 33 +++++------ .../html/class_HtmlLoginFailedCommand.php | 33 +++++------ .../html/class_HtmlLogoutDoneCommand.php | 33 +++++------ .../html/class_HtmlRegisterCommand.php | 35 ++++++------ .../html/class_HtmlResendLinkCommand.php | 9 +-- .../commands/html/class_HtmlStatusCommand.php | 31 +++++------ .../image/class_ImageCodeCaptchaCommand.php | 13 ++--- .../main/classes/images/class_BaseImage.php | 39 ++++++------- .../command/class_BaseCommandResolver.php | 34 +++++++----- .../class_BaseControllerResolver.php | 5 +- .../console/class_ConsoleResponse.php | 12 +--- .../response/html/class_HtmlResponse.php | 14 +---- .../response/image/class_ImageResponse.php | 30 ++-------- .../mail/class_MailTemplateEngine.php | 3 + .../menu/class_MenuTemplateEngine.php | 28 ++++------ .../actions/commands/class_Commandable.php | 8 +++ .../commands/class_CommandResolver.php | 22 +++++++- .../response/class_Responseable.php | 12 +--- .../class_TestsConsoleControllerResolver.php | 32 ----------- 26 files changed, 256 insertions(+), 386 deletions(-) diff --git a/framework/bootstrap/class_FrameworkBootstrap.php b/framework/bootstrap/class_FrameworkBootstrap.php index 2f73941b..b102c976 100644 --- a/framework/bootstrap/class_FrameworkBootstrap.php +++ b/framework/bootstrap/class_FrameworkBootstrap.php @@ -364,9 +364,6 @@ final class FrameworkBootstrap { )); } - // Init template engine - self::getResponseInstance()->initTemplateEngine($applicationInstance); - // Now call all methods in one go foreach (array('setupApplicationData', 'initApplication', 'launchApplication') as $methodName) { // Debug message diff --git a/framework/config-global.php b/framework/config-global.php index 8ba651e3..bc964adf 100644 --- a/framework/config-global.php +++ b/framework/config-global.php @@ -436,6 +436,9 @@ $cfg->setConfigEntry('default_image_controller', 'build'); // CFG: MENU-TEMPLATE-CLASS $cfg->setConfigEntry('menu_template_class', 'Org\Mxchange\CoreFramework\Template\Engine\MenuTemplateEngine'); +// CFG: CONSOLE-TEMPLATE-CLASS +$cfg->setConfigEntry('console_template_class', 'Org\Mxchange\CoreFramework\Template\Engine\ConsoleTemplateEngine'); + // CFG: MENU-TEMPLATE-EXTENSION $cfg->setConfigEntry('menu_template_extension', '.xml'); diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index 3f68e5b8..b6e5924f 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -30,7 +30,6 @@ use Org\Mxchange\CoreFramework\State\Stateable; use Org\Mxchange\CoreFramework\Stream\Input\InputStream; use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer; use Org\Mxchange\CoreFramework\Stream\Output\OutputStream; -use Org\Mxchange\CoreFramework\Template\CompileableTemplate; use Org\Mxchange\CoreFramework\User\ManageableAccount; use Org\Mxchange\CoreFramework\Utils\String\StringUtils; @@ -90,11 +89,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac */ private $updateInstance = NULL; - /** - * Template engine instance - */ - private $templateInstance = NULL; - /** * Database result instance */ @@ -496,25 +490,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac return $this->resultInstance; } - /** - * Setter for template engine instances - * - * @param $templateInstance An instance of a template engine class - * @return void - */ - protected final function setTemplateInstance (CompileableTemplate $templateInstance) { - $this->templateInstance = $templateInstance; - } - - /** - * Getter for template engine instances - * - * @return $templateInstance An instance of a template engine class - */ - protected final function getTemplateInstance () { - return $this->templateInstance; - } - /** * Setter for search instance * @@ -872,36 +847,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac return $str; } - /** - * Prepare the template engine (HtmlTemplateEngine by default) for a given - * application helper instance (ApplicationHelper by default). - * - * @param $applicationInstance An application helper instance or - * null if we shall use the default - * @return $templateInstance The template engine instance - * @throws NullPointerException If the discovered application - * instance is still null - */ - protected function prepareTemplateInstance (ManageableApplication $applicationInstance = NULL) { - // Is the application instance set? - if (is_null($applicationInstance)) { - // Get the current instance - $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - - // Still null? - if (is_null($applicationInstance)) { - // Thrown an exception - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } // END - if - } // END - if - - // Initialize the template engine - $templateInstance = ObjectFactory::createObjectByConfiguredName('html_template_class'); - - // Return the prepared instance - return $templateInstance; - } - /** * Debugs this instance by putting out it's full content * diff --git a/framework/main/classes/commands/class_BaseCommand.php b/framework/main/classes/commands/class_BaseCommand.php index 2b713df3..c7e0e9e0 100644 --- a/framework/main/classes/commands/class_BaseCommand.php +++ b/framework/main/classes/commands/class_BaseCommand.php @@ -49,6 +49,20 @@ abstract class BaseCommand extends BaseFrameworkSystem { parent::__construct($className); } + /** + * Initializes the template engine + * + * @param $templateType Type of template, e.g. 'html', 'image', 'console' ... + * @return void + */ + public final function initTemplateEngine (string $templateType) { + // Prepare a template instance + $templateInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_template_class', $templateType)); + + // Set it here + $this->setTemplateInstance($templateInstance); + } + /** * Setter for resolver instance * @@ -76,50 +90,47 @@ abstract class BaseCommand extends BaseFrameworkSystem { * @param $suffix Optional template suffix, e.g. '_form' for forms * @return void */ - protected function sendGenericGetResponse (Requestable $requestInstance, Responseable $responseInstance, $suffix = '') { + protected function sendGenericGetResponse (Requestable $requestInstance, Responseable $responseInstance, string $suffix = '') { // This command doesn't handle any POST requests, so only handle get request assert(!$requestInstance->isPostRequestMethod()); // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Transfer application data - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the content template - $templateInstance->loadCodeTemplate($this->getResolverInstance()->getCommandName() . $suffix); + $this->getTemplateInstance()->loadCodeTemplate($this->getResolverInstance()->getCommandName() . $suffix); // Assign the content template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable($applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName(), 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable($applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName(), 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_' . $applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName() . '_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('page_' . $applicationInstance->getAppShortName() . '_' . $this->getResolverInstance()->getCommandName() . '_title')); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -129,17 +140,17 @@ abstract class BaseCommand extends BaseFrameworkSystem { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } } diff --git a/framework/main/classes/commands/html/class_HtmlConfirmCommand.php b/framework/main/classes/commands/html/class_HtmlConfirmCommand.php index f7f3c0b6..3401e1eb 100644 --- a/framework/main/classes/commands/html/class_HtmlConfirmCommand.php +++ b/framework/main/classes/commands/html/class_HtmlConfirmCommand.php @@ -75,43 +75,40 @@ class HtmlConfirmCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign application data with template engine - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the home template - $templateInstance->loadCodeTemplate('confirm_link'); + $this->getTemplateInstance()->loadCodeTemplate('confirm_link'); // Assign the home template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable('confirm_link', 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable('confirm_link', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_confirm_link_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('page_confirm_link_title')); // Get user instance try { @@ -122,7 +119,7 @@ class HtmlConfirmCommand extends BaseCommand implements Commandable { } // Set username - $templateInstance->assignVariable('username', $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USERNAME)); + $this->getTemplateInstance()->assignVariable('username', $userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USERNAME)); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -132,17 +129,17 @@ class HtmlConfirmCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlHomeCommand.php b/framework/main/classes/commands/html/class_HtmlHomeCommand.php index c9297866..91a69c31 100644 --- a/framework/main/classes/commands/html/class_HtmlHomeCommand.php +++ b/framework/main/classes/commands/html/class_HtmlHomeCommand.php @@ -74,39 +74,37 @@ class HtmlHomeCommand extends BaseCommand implements Commandable { $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Transfer application data - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the home template - $templateInstance->loadCodeTemplate('home'); + $this->getTemplateInstance()->loadCodeTemplate('home'); // Assign the home template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable('home', 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable('home', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_home_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('page_home_title')); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -116,17 +114,17 @@ class HtmlHomeCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php b/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php index e7859fa9..266ba7c4 100644 --- a/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php +++ b/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php @@ -102,51 +102,48 @@ class HtmlLoginAreaCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Assign all the application's data with template variables - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the matching template - $templateInstance->loadCodeTemplate('action_' . $this->actionName); + $this->getTemplateInstance()->loadCodeTemplate('action_' . $this->actionName); // Assign the template with the master template as a content ... ;) - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('action_' . $this->actionName, 'login_content'); // Load main template - $templateInstance->loadCodeTemplate('login_main'); + $this->getTemplateInstance()->loadCodeTemplate('login_main'); // Assign the main template with the master template as a content ... ;) - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('login_main', 'main_content'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('login_main', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title')); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -156,17 +153,17 @@ class HtmlLoginAreaCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlLoginCommand.php b/framework/main/classes/commands/html/class_HtmlLoginCommand.php index eeca1e8e..cef2596d 100644 --- a/framework/main/classes/commands/html/class_HtmlLoginCommand.php +++ b/framework/main/classes/commands/html/class_HtmlLoginCommand.php @@ -76,43 +76,40 @@ class HtmlLoginCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign application data with template engine - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the home template - $templateInstance->loadCodeTemplate('login_form'); + $this->getTemplateInstance()->loadCodeTemplate('login_form'); // Assign the home template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable('login_form', 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable('login_form', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_login_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('page_login_title')); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -122,17 +119,17 @@ class HtmlLoginCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlLoginFailedCommand.php b/framework/main/classes/commands/html/class_HtmlLoginFailedCommand.php index 2c380e01..24356c36 100644 --- a/framework/main/classes/commands/html/class_HtmlLoginFailedCommand.php +++ b/framework/main/classes/commands/html/class_HtmlLoginFailedCommand.php @@ -73,43 +73,40 @@ class HtmlLoginFailedCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign application data with template engine - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the login_failed template - $templateInstance->loadCodeTemplate('login_failed'); + $this->getTemplateInstance()->loadCodeTemplate('login_failed'); // Assign the login_failed template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable('login_failed', 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable('login_failed', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('login_failed_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('login_failed_title')); // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -119,17 +116,17 @@ class HtmlLoginFailedCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlLogoutDoneCommand.php b/framework/main/classes/commands/html/class_HtmlLogoutDoneCommand.php index 92384e59..a7134cb6 100644 --- a/framework/main/classes/commands/html/class_HtmlLogoutDoneCommand.php +++ b/framework/main/classes/commands/html/class_HtmlLogoutDoneCommand.php @@ -73,43 +73,40 @@ class HtmlLogoutDoneCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign application data - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the logout_done template - $templateInstance->loadCodeTemplate('logout_done'); + $this->getTemplateInstance()->loadCodeTemplate('logout_done'); // Assign the logout_done template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable('logout_done', 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable('logout_done', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('logout_done_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('logout_done_title')); // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -119,17 +116,17 @@ class HtmlLogoutDoneCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlRegisterCommand.php b/framework/main/classes/commands/html/class_HtmlRegisterCommand.php index 619bfabf..3a223a7d 100644 --- a/framework/main/classes/commands/html/class_HtmlRegisterCommand.php +++ b/framework/main/classes/commands/html/class_HtmlRegisterCommand.php @@ -76,44 +76,41 @@ class HtmlRegisterCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign all the application's data with template variables - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Assign base URL - $templateInstance->assignConfigVariable('base_url'); + $this->getTemplateInstance()->assignConfigVariable('base_url'); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the register template - $templateInstance->loadCodeTemplate('register_form'); + $this->getTemplateInstance()->loadCodeTemplate('register_form'); // Assign the register template with the master template as a content ... ;) - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('register_form', 'main_content'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('register_form', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_register_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('page_register_title')); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -123,17 +120,17 @@ class HtmlRegisterCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php b/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php index db4c6877..72e24a68 100644 --- a/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php +++ b/framework/main/classes/commands/html/class_HtmlResendLinkCommand.php @@ -96,17 +96,14 @@ class HtmlResendLinkCommand extends BaseCommand implements Commandable { // Re-set config entry to mailer engine FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('html_template_class', FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('mail_template_class')); - // Prepare the template engine - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign the application data with the template engine - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Get a mailer class - $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance, 'resend_link')); + $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($this->getTemplateInstance(), 'resend_link')); // Set this mailer in our template engine - $templateInstance->setMailerInstance($mailerInstance); + $this->getTemplateInstance()->setMailerInstance($mailerInstance); // Add template variables we shall get $mailerInstance->addConfigTemplateVariable('base_url'); diff --git a/framework/main/classes/commands/html/class_HtmlStatusCommand.php b/framework/main/classes/commands/html/class_HtmlStatusCommand.php index 8c4aec9b..e829e11a 100644 --- a/framework/main/classes/commands/html/class_HtmlStatusCommand.php +++ b/framework/main/classes/commands/html/class_HtmlStatusCommand.php @@ -73,40 +73,37 @@ class HtmlStatusCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Transfer application data - $templateInstance->assignApplicationData(); + $this->getTemplateInstance()->assignApplicationData(); // Load the master template $masterTemplate = $applicationInstance->buildMasterTemplateName(); // Load header template - $templateInstance->loadCodeTemplate('header'); + $this->getTemplateInstance()->loadCodeTemplate('header'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('header', 'header'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header'); // Load footer template - $templateInstance->loadCodeTemplate('footer'); + $this->getTemplateInstance()->loadCodeTemplate('footer'); // Compile and assign it with a variable - $templateInstance->compileTemplate(); - $templateInstance->assignTemplateWithVariable('footer', 'footer'); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer'); // Load the status template - $templateInstance->loadCodeTemplate('status'); + $this->getTemplateInstance()->loadCodeTemplate('status'); // Assign the status template with the master template as a content ... ;) - $templateInstance->assignTemplateWithVariable('status', 'main_content'); + $this->getTemplateInstance()->assignTemplateWithVariable('status', 'main_content'); // Load the master template - $templateInstance->loadCodeTemplate($masterTemplate); + $this->getTemplateInstance()->loadCodeTemplate($masterTemplate); // Set title - $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_status_title')); + $this->getTemplateInstance()->assignVariable('title', $this->getLanguageInstance()->getMessage('page_status_title')); // Construct the menu in every command. We could do this in BaseCommand class. But this means // *every* command has a navigation system and that is want we don't want. @@ -116,17 +113,17 @@ class HtmlStatusCommand extends BaseCommand implements Commandable { $menuInstance->renderMenu(); // Transfer it to the template engine instance - $menuInstance->transferContentToTemplateEngine($templateInstance); + $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance()); /* * ... and all variables. This should be merged together in a pattern * to make things easier. A cache mechanism should be added between * these two calls to cache compiled templates. */ - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Get the content back from the template engine and put it in response class - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/commands/image/class_ImageCodeCaptchaCommand.php b/framework/main/classes/commands/image/class_ImageCodeCaptchaCommand.php index 4636636e..ea5f737d 100644 --- a/framework/main/classes/commands/image/class_ImageCodeCaptchaCommand.php +++ b/framework/main/classes/commands/image/class_ImageCodeCaptchaCommand.php @@ -75,23 +75,20 @@ class ImageCodeCaptchaCommand extends BaseCommand implements Commandable { // Get the application instance $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); - // Prepare a template instance - $templateInstance = $this->prepareTemplateInstance($applicationInstance); - // Assign variable - $templateInstance->assignVariable('decrypted_code', $decryptedCode); + $this->getTemplateInstance()->assignVariable('decrypted_code', $decryptedCode); // Load the code (pardon, image...) template - $templateInstance->loadCodeTemplate('code_captcha'); + $this->getTemplateInstance()->loadCodeTemplate('code_captcha'); // Compile the template - $templateInstance->compileTemplate(); + $this->getTemplateInstance()->compileTemplate(); // Compile all variables - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileVariables(); // Transfer it to the response - $templateInstance->transferToResponse($responseInstance); + $this->getTemplateInstance()->transferToResponse($responseInstance); } /** diff --git a/framework/main/classes/images/class_BaseImage.php b/framework/main/classes/images/class_BaseImage.php index ae8fb1b2..cb08935a 100644 --- a/framework/main/classes/images/class_BaseImage.php +++ b/framework/main/classes/images/class_BaseImage.php @@ -462,12 +462,9 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { * @return void */ public function finishImage () { - // Get template instance - $templateInstance = $this->getTemplateInstance(); - // Compile width and height - $width = $templateInstance->compileRawCode($this->getWidth()); - $height = $templateInstance->compileRawCode($this->getHeight()); + $width = $this->getTemplateInstance()->compileRawCode($this->getWidth()); + $height = $this->getTemplateInstance()->compileRawCode($this->getHeight()); // Set both again $this->setWidth($width); @@ -477,9 +474,9 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { $this->imageResource = imagecreatetruecolor($width, $height); // Compile background colors - $red = $templateInstance->compileRawCode($this->backgroundColor['red']); - $green = $templateInstance->compileRawCode($this->backgroundColor['green']); - $blue = $templateInstance->compileRawCode($this->backgroundColor['blue']); + $red = $this->getTemplateInstance()->compileRawCode($this->backgroundColor['red']); + $green = $this->getTemplateInstance()->compileRawCode($this->backgroundColor['green']); + $blue = $this->getTemplateInstance()->compileRawCode($this->backgroundColor['blue']); // Set all back $this->initBackgroundColor(); @@ -494,9 +491,9 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { imagefill($this->getImageResource(), 0, 0, $backColor); // Compile foreground colors - $red = $templateInstance->compileRawCode($this->foregroundColor['red']); - $green = $templateInstance->compileRawCode($this->foregroundColor['green']); - $blue = $templateInstance->compileRawCode($this->foregroundColor['blue']); + $red = $this->getTemplateInstance()->compileRawCode($this->foregroundColor['red']); + $green = $this->getTemplateInstance()->compileRawCode($this->foregroundColor['green']); + $blue = $this->getTemplateInstance()->compileRawCode($this->foregroundColor['blue']); // Set all fore $this->initForegroundColor(); @@ -510,15 +507,15 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { switch ($this->groupable) { case 'single': // Single image string // Compile image string - $imageString = $templateInstance->compileRawCode($this->getString()); + $imageString = $this->getTemplateInstance()->compileRawCode($this->getString()); // Set it back $this->setString($imageString); // Compile X/Y coordinates and font size - $x = $templateInstance->compileRawCode($this->getX()); - $y = $templateInstance->compileRawCode($this->getY()); - $size = $templateInstance->compileRawCode($this->getFontSize()); + $x = $this->getTemplateInstance()->compileRawCode($this->getX()); + $y = $this->getTemplateInstance()->compileRawCode($this->getY()); + $size = $this->getTemplateInstance()->compileRawCode($this->getFontSize()); // Set the image string imagestring($this->getImageResource(), $size, $x, $y, $imageString, $foreColor); @@ -526,17 +523,17 @@ abstract class BaseImage extends BaseFrameworkSystem implements Registerable { case 'groupable': // More than one string allowed // Walk through all groups - foreach ($templateInstance->getVariableGroups() as $group => $set) { + foreach ($this->getTemplateInstance()->getVariableGroups() as $group => $set) { // Set the group - $templateInstance->setVariableGroup($group, false); + $this->getTemplateInstance()->setVariableGroup($group, false); // Compile image string - $imageString = $templateInstance->compileRawCode($this->getString()); + $imageString = $this->getTemplateInstance()->compileRawCode($this->getString()); // Compile X/Y coordinates and font size - $x = $templateInstance->compileRawCode($this->getX()); - $y = $templateInstance->compileRawCode($this->getY()); - $size = $templateInstance->compileRawCode($this->getFontSize()); + $x = $this->getTemplateInstance()->compileRawCode($this->getX()); + $y = $this->getTemplateInstance()->compileRawCode($this->getY()); + $size = $this->getTemplateInstance()->compileRawCode($this->getFontSize()); // Set the image string //* DEBUG: */ print __METHOD__.": size={$size}, x={$x}, y={$y}, string={$imageString}
\n"; diff --git a/framework/main/classes/resolver/command/class_BaseCommandResolver.php b/framework/main/classes/resolver/command/class_BaseCommandResolver.php index bb1b0965..53a24d61 100644 --- a/framework/main/classes/resolver/command/class_BaseCommandResolver.php +++ b/framework/main/classes/resolver/command/class_BaseCommandResolver.php @@ -100,7 +100,7 @@ abstract class BaseCommandResolver extends BaseResolver { if (!class_exists($this->getClassName())) { // Class not found, so throw an exception throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if + } // Initiate the command $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this)); @@ -120,22 +120,21 @@ abstract class BaseCommandResolver extends BaseResolver { */ public function resolveCommandByRequest (Requestable $requestInstance) { // Init variables - $commandName = ''; - $commandInstance = NULL; - - // This goes fine so let's resolve the command $commandName = $requestInstance->getRequestElement('command'); + $commandType = FrameworkBootstrap::getRequestTypeFromSystem(); + $commandInstance = NULL; // Is the command empty? Then fall back to default command if (empty($commandName)) { - $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command'); - } // END - if + // Fall back to default command + $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry(sprintf('default_%s_command', $commandType)); + } // Check if command is valid if ($this->isCommandValid($this->getNamespace(), $commandName) === false) { // This command is invalid! throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if + } // Get the command $commandInstance = $this->loadCommand($commandName); @@ -144,11 +143,14 @@ abstract class BaseCommandResolver extends BaseResolver { if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { // This command has an invalid instance! throw new UnexpectedValueException(sprintf('commandInstance for commandName=%s is not object (%s) or does not implement Commandable.', $commandName, gettype($commandInstance)), self::EXCEPTION_INVALID_COMMAND); - } // END - if + } // Set last command $this->setResolvedInstance($commandInstance); + // Init template engine + $commandInstance->initTemplateEngine($commandType); + // Return the resolved command instance return $commandInstance; } @@ -161,7 +163,7 @@ abstract class BaseCommandResolver extends BaseResolver { * @return $commandInstance An instance of the command class * @throws InvalidCommandException Thrown if $commandName is invalid */ - public function resolveCommand ($namespace, $commandName) { + public function resolveCommand (string $namespace, string $commandName) { // Is a action set? if (empty($namespace)) { // Then thrown an exception here @@ -173,22 +175,26 @@ abstract class BaseCommandResolver extends BaseResolver { // Initiate the instance variable $commandInstance = NULL; + $commandType = FrameworkBootstrap::getRequestTypeFromSystem(); // Is the command empty? Then fall back to default command if (empty($commandName)) { // Init default command - $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('default_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command'); - } // END - if + $commandName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry(sprintf('default_%s_command', $commandType)); + } // Check if command is valid if ($this->isCommandValid($namespace, $commandName) === false) { // This command is invalid! throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } // END - if + } // Get the command $commandInstance = $this->loadCommand($commandName); + // Init template engine + $commandInstance->initTemplateEngine($commandType); + // Return the instance return $commandInstance; } @@ -229,7 +235,7 @@ abstract class BaseCommandResolver extends BaseResolver { if (class_exists($this->getClassName())) { // This class does exist. :-) $isValid = true; - } // END - if + } // Set command name $this->setCommandName($commandName); diff --git a/framework/main/classes/resolver/controller/class_BaseControllerResolver.php b/framework/main/classes/resolver/controller/class_BaseControllerResolver.php index 12281e34..c3b45fca 100644 --- a/framework/main/classes/resolver/controller/class_BaseControllerResolver.php +++ b/framework/main/classes/resolver/controller/class_BaseControllerResolver.php @@ -219,11 +219,8 @@ abstract class BaseControllerResolver extends BaseResolver { */ public function resolveController () { // Init variables - $controllerName = ''; - $controllerInstance = NULL; - - // Get namespace and controller name $controllerName = $this->getControllerName(); + $controllerInstance = NULL; // Get the controller $controllerInstance = $this->loadController($controllerName); diff --git a/framework/main/classes/response/console/class_ConsoleResponse.php b/framework/main/classes/response/console/class_ConsoleResponse.php index 6d5d6df4..cdd53a20 100644 --- a/framework/main/classes/response/console/class_ConsoleResponse.php +++ b/framework/main/classes/response/console/class_ConsoleResponse.php @@ -58,16 +58,6 @@ class ConsoleResponse extends BaseResponse implements Responseable { return $responseInstance; } - /** - * Initializes the template engine instance - * - * @param $applicationInstance An instance of a manageable application - * @return void - */ - public final function initTemplateEngine (ManageableApplication $applicationInstance) { - $this->setTemplateInstance($this->prepareTemplateInstance($applicationInstance)); - } - /** * Adds a cookie to the response * @@ -78,7 +68,7 @@ class ConsoleResponse extends BaseResponse implements Responseable { * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = NULL) { + public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { //* DEBUG: */ echo $cookieName.'='.$cookieValue."
\n"; $this->partialStub('Naturally unimplemented in console response.'); } diff --git a/framework/main/classes/response/html/class_HtmlResponse.php b/framework/main/classes/response/html/class_HtmlResponse.php index 62cf8800..2cba458d 100644 --- a/framework/main/classes/response/html/class_HtmlResponse.php +++ b/framework/main/classes/response/html/class_HtmlResponse.php @@ -60,16 +60,6 @@ class HtmlResponse extends BaseResponse implements Responseable { return $responseInstance; } - /** - * Initializes the template engine instance - * - * @param $applicationInstance An instance of a manageable application - * @return void - */ - public final function initTemplateEngine (ManageableApplication $applicationInstance) { - $this->setTemplateInstance($this->prepareTemplateInstance($applicationInstance)); - } - /** * Adds a cookie to the response * @@ -84,7 +74,7 @@ class HtmlResponse extends BaseResponse implements Responseable { * @todo If the return statement is removed and setcookie() commented out, * @todo this will send only one cookie out, the first one. */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = NULL) { + public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { //* DEBUG: */ echo $cookieName.'='.$cookieValue."
\n"; // Are headers already sent? if (headers_sent()) { @@ -94,7 +84,7 @@ class HtmlResponse extends BaseResponse implements Responseable { } // END - if // Shall we encrypt the cookie? - if ($encrypted === true) { + if ($encrypted) { // Unsupported at the moment $this->partialStub('Encryption is unsupported at the moment.'); } // END - if diff --git a/framework/main/classes/response/image/class_ImageResponse.php b/framework/main/classes/response/image/class_ImageResponse.php index e6b7eff0..5354c0ec 100644 --- a/framework/main/classes/response/image/class_ImageResponse.php +++ b/framework/main/classes/response/image/class_ImageResponse.php @@ -85,28 +85,6 @@ class ImageResponse extends BaseResponse implements Responseable { return $this->imageInstance; } - /** - * Initializes the template engine instance - * - * @param $applicationInstance An instance of a manageable application - * @return void - */ - public final function initTemplateEngine (ManageableApplication $applicationInstance) { - // Get config instance - $cfg = FrameworkBootstrap::getConfigurationInstance(); - - // Set new template engine - $cfg->setConfigEntry('html_template_class' , $cfg->getConfigEntry('image_template_class')); - $cfg->setConfigEntry('raw_template_extension' , '.img'); - $cfg->setConfigEntry('code_template_extension', '.xml'); - $cfg->setConfigEntry('tpl_base_path' , 'templates/images/'); - // @TODO Please fix this - $cfg->setConfigEntry('code_template_type' , 'image'); - - // Get a prepared instance - $this->setTemplateInstance($this->prepareTemplateInstance($applicationInstance)); - } - /** * Adds a cookie to the response * @@ -121,18 +99,18 @@ class ImageResponse extends BaseResponse implements Responseable { * @todo If the return statement is removed and setcookie() commented out, * @todo this will send only one cookie out, the first one. */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = NULL) { + public function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL) { // Are headers already sent? if (headers_sent()) { // Throw an exception here throw new ResponseHeadersAlreadySentException($this, self::EXCEPTION_HEADERS_ALREADY_SENT); - } // END - if + } // Shall we encrypt the cookie? - if ($encrypted === true) { + if ($encrypted) { // Unsupported at the moment $this->partialStub('Encryption is unsupported at the moment.'); - } // END - if + } // For slow browsers set the cookie array element first $_COOKIE[$cookieName] = $cookieValue; diff --git a/framework/main/classes/template/mail/class_MailTemplateEngine.php b/framework/main/classes/template/mail/class_MailTemplateEngine.php index a442cf1e..9263be58 100644 --- a/framework/main/classes/template/mail/class_MailTemplateEngine.php +++ b/framework/main/classes/template/mail/class_MailTemplateEngine.php @@ -75,6 +75,9 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set template type + $this->setTemplateType('mail'); } /** diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index 67fdedb9..a0ff0309 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -803,11 +803,8 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla * @return void */ private function renderMenuEntry () { - // Prepare template engine - $templateInstance = $this->prepareTemplateInstance(); - // Load menu entry template - $templateInstance->loadCodeTemplate('menu_entry'); + $this->getTemplateInstance()->loadCodeTemplate('menu_entry'); // Copy all variables over to it foreach ($this->menuEntryVariables as $variableName) { @@ -821,15 +818,15 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla } // END - if // ... into the instance - $templateInstance->assignVariable($variableName, $variableValue); + $this->getTemplateInstance()->assignVariable($variableName, $variableValue); } // END - foreach // Compile template + variables - $templateInstance->compileTemplate(); - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->compileVariables(); // Remember it here - $this->menuEntries[$this->readVariable('entry_id')] = $templateInstance->getRawTemplateData(); + $this->menuEntries[$this->readVariable('entry_id')] = $this->getTemplateInstance()->getRawTemplateData(); } /** @@ -842,11 +839,8 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla // Init block content $blockContent = implode('', $this->menuEntries); - // Prepare template engine - $templateInstance = $this->prepareTemplateInstance(); - // Load menu entry template - $templateInstance->loadCodeTemplate('menu_block'); + $this->getTemplateInstance()->loadCodeTemplate('menu_block'); // Copy all variables over to it foreach ($this->menuBlockVariables as $variableName) { @@ -854,18 +848,18 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla $variableValue = $this->readVariable($variableName); // ... into the instance - $templateInstance->assignVariable($variableName, $variableValue); + $this->getTemplateInstance()->assignVariable($variableName, $variableValue); } // END - foreach // Assign block content - $templateInstance->assignVariable('block_content', $blockContent); + $this->getTemplateInstance()->assignVariable('block_content', $blockContent); // Compile template + variables - $templateInstance->compileTemplate(); - $templateInstance->compileVariables(); + $this->getTemplateInstance()->compileTemplate(); + $this->getTemplateInstance()->compileVariables(); // Remember it here - array_push($this->menuBlocks, $templateInstance->getRawTemplateData()); + array_push($this->menuBlocks, $this->getTemplateInstance()->getRawTemplateData()); // Reset rendered menu entries array $this->menuEntries = array(); diff --git a/framework/main/interfaces/actions/commands/class_Commandable.php b/framework/main/interfaces/actions/commands/class_Commandable.php index ae1c4579..e458c571 100644 --- a/framework/main/interfaces/actions/commands/class_Commandable.php +++ b/framework/main/interfaces/actions/commands/class_Commandable.php @@ -39,4 +39,12 @@ interface Commandable extends PerformableAction { */ function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance); + /** + * Initializes the template engine + * + * @param $templateType Type of template, e.g. 'html', 'image', 'console' ... + * @return void + */ + function initTemplateEngine (string $templateType); + } diff --git a/framework/main/interfaces/resolver/commands/class_CommandResolver.php b/framework/main/interfaces/resolver/commands/class_CommandResolver.php index b8d4b55a..73100caf 100644 --- a/framework/main/interfaces/resolver/commands/class_CommandResolver.php +++ b/framework/main/interfaces/resolver/commands/class_CommandResolver.php @@ -30,11 +30,31 @@ use Org\Mxchange\CoreFramework\Resolver\Resolver; */ interface CommandResolver extends Resolver { /** - * Returns an command instance for a given request class + * Getter for command name + * + * @return $commandName Last validated command name + */ + function getCommandName (); + + /** + * Returns an command instance for a given request class or null if + * it was not found * * @param $requestInstance An instance of a Requestable class * @return $commandInstance An instance of the resolved command + * @throws InvalidCommandException Thrown if $commandName is invalid + * @throws UnexpectedValueException Thrown if $commandInstance is an invalid instance */ function resolveCommandByRequest (Requestable $requestInstance); + /** + * Resolves the command by its direct name and returns an instance of its class + * + * @param $namespace Namespace to look in + * @param $commandName The direct command name we shall resolve + * @return $commandInstance An instance of the command class + * @throws InvalidCommandException Thrown if $commandName is invalid + */ + function resolveCommand (string $namespace, string $commandName); + } diff --git a/framework/main/interfaces/response/class_Responseable.php b/framework/main/interfaces/response/class_Responseable.php index 0713ab78..0a302497 100644 --- a/framework/main/interfaces/response/class_Responseable.php +++ b/framework/main/interfaces/response/class_Responseable.php @@ -4,7 +4,6 @@ namespace Org\Mxchange\CoreFramework\Response; // Import framework stuff use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; -use Org\Mxchange\CoreFramework\Manager\ManageableApplication; /** * An interface for responses @@ -84,10 +83,11 @@ interface Responseable extends FrameworkInterface { * @param $cookieName Cookie's name * @param $cookieValue Value to store in the cookie * @param $encrypted Do some extra encryption on the value + * @param $expires Timestamp of expiration (default: configured) * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - function addCookie ($cookieName, $cookieValue, $encrypted = false); + function addCookie (string $cookieName, $cookieValue, bool $encrypted = FALSE, int $expires = NULL); /** * Redirect to a configured URL. The URL can be absolute or relative. In @@ -116,12 +116,4 @@ interface Responseable extends FrameworkInterface { */ function refreshCookie ($cookieName); - /** - * Initializes the template engine instance - * - * @param $applicationInstance An instance of a manageable application - * @return void - */ - function initTemplateEngine (ManageableApplication $applicationInstance); - } diff --git a/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php b/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php index 522a3c6c..4ab501d7 100644 --- a/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php +++ b/framework/main/tests/resolver/controller/class_TestsConsoleControllerResolver.php @@ -77,36 +77,4 @@ class TestsConsoleControllerResolver extends BaseControllerResolver implements C return $resolverInstance; } - /** - * Resolves the default controller of the given command - * - * @return $controllerInstance A controller instance for the default - * command - * @throws InvalidControllerInstanceException Thrown if $controllerInstance - * is invalid - */ - public function resolveController () { - // Init variables - $controllerName = ''; - $controllerInstance = NULL; - - // Get namespace and command name - $controllerName = $this->getControllerName(); - - // Get the command - $controllerInstance = $this->loadController($controllerName); - - // And validate it - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // This command has an invalid instance! - throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); - } // END - if - - // Set last controller - $this->setResolvedInstance($controllerInstance); - - // Return the maybe resolved instance - return $controllerInstance; - } - } -- 2.39.2