3 namespace Org\Mxchange\CoreFramework\Command\Login;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Action\PerformableAction;
7 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
8 use Org\Mxchange\CoreFramework\Command\BaseCommand;
9 use Org\Mxchange\CoreFramework\Command\Commandable;
10 use Org\Mxchange\CoreFramework\Controller\Controller;
11 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
12 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
13 use Org\Mxchange\CoreFramework\Request\Requestable;
14 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
15 use Org\Mxchange\CoreFramework\Response\Responseable;
16 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
19 * A command for the login area (member/gamer area)
21 * @author Roland Haeder <webmaster@shipsimu.org>
23 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
27 * This program is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
44 private $actionName = '';
47 * Protected constructor
51 protected function __construct () {
52 // Call parent constructor
53 parent::__construct(__CLASS__);
57 * Creates an instance of this class
59 * @param $resolverInstance An instance of a command resolver class
60 * @return $commandInstance An instance a prepared command class
62 public static final function createHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
64 $commandInstance = new HtmlLoginAreaCommand();
66 // Set the application instance
67 $commandInstance->setResolverInstance($resolverInstance);
69 // Load general data like user status and such
70 $commandInstance->prepareCommand();
72 // Return the prepared instance
73 return $commandInstance;
77 * Prepares some general data which shall be displayed on every page
80 * @todo Add some stuff here: Some personal data, app/game related data
82 protected function prepareCommand () {
86 * Executes the given command with given request and response objects
88 * @param $requestInstance An instance of a class with an Requestable interface
89 * @param $responseInstance An instance of a class with an Responseable interface
92 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
93 // Get the action instance from registry
94 $actionInstance = GenericRegistry::getRegistry()->getInstance('action');
96 // Do we have an action here?
97 if ($actionInstance instanceof PerformableAction) {
98 // Execute the action (shall not output anything, see below why)
99 $actionInstance->execute($requestInstance, $responseInstance);
102 // Get the application instance
103 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
106 $this->getTemplateInstance()->assignConfigVariable('base_url');
108 // Assign all the application's data with template variables
109 $this->getTemplateInstance()->assignApplicationData();
111 // Load the master template
112 $masterTemplate = $applicationInstance->buildMasterTemplateName();
114 // Load header template
115 $this->getTemplateInstance()->loadCodeTemplate('header');
117 // Compile and assign it with a variable
118 $this->getTemplateInstance()->compileTemplate();
119 $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header');
121 // Load footer template
122 $this->getTemplateInstance()->loadCodeTemplate('footer');
124 // Compile and assign it with a variable
125 $this->getTemplateInstance()->compileTemplate();
126 $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer');
128 // Load the matching template
129 $this->getTemplateInstance()->loadCodeTemplate('action_' . $this->actionName);
131 // Assign the template with the master template as a content ... ;)
132 $this->getTemplateInstance()->compileTemplate();
133 $this->getTemplateInstance()->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
135 // Load main template
136 $this->getTemplateInstance()->loadCodeTemplate('login_main');
138 // Assign the main template with the master template as a content ... ;)
139 $this->getTemplateInstance()->compileTemplate();
140 $this->getTemplateInstance()->assignTemplateWithVariable('login_main', 'main_content');
142 // Load the master template
143 $this->getTemplateInstance()->loadCodeTemplate($masterTemplate);
146 $this->getTemplateInstance()->assignVariable('title', FrameworkBootstrap::getLanguageInstance()->getMessage($this->actionName . '_title'));
148 // Construct the menu in every command. We could do this in BaseCommand class. But this means
149 // *every* command has a navigation system and that is want we don't want.
150 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
153 $menuInstance->renderMenu();
155 // Transfer it to the template engine instance
156 $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance());
159 * ... and all variables. This should be merged together in a pattern
160 * to make things easier. A cache mechanism should be added between
161 * these two calls to cache compiled templates.
163 $this->getTemplateInstance()->compileVariables();
165 // Get the content back from the template engine and put it in response class
166 $this->getTemplateInstance()->transferToResponse($responseInstance);
170 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
172 * @param $controllerInstance A controller instance
173 * @param $requestInstance An instance of a class with an Requestable interface
176 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
178 $registryInstance = GenericRegistry::getRegistry();
180 // Get our application instance from the registry
181 $applicationInstance = $registryInstance->getInstance('application');
183 // Default action is the one from configuration
184 $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_default_action');
186 // Get "action" from request
187 $actReq = $requestInstance->getRequestElement('action');
189 // Do we have a "action" parameter set?
190 if ((is_string($actReq)) && (!empty($actReq))) {
191 // Then use it with prefix
192 $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
196 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName);
198 // Resolve the action
199 $actionInstance = $actionResolver->resolveAction();
201 // Add more action-specific filters
202 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
204 // Remember this action in registry
205 GenericRegistry::getRegistry()->addInstance('action', $actionInstance);