3 namespace Org\Mxchange\CoreFramework\Command\Login;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Action\PerformableAction;
7 use Org\Mxchange\CoreFramework\Command\BaseCommand;
8 use Org\Mxchange\CoreFramework\Command\Commandable;
9 use Org\Mxchange\CoreFramework\Controller\Controller;
10 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
11 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
12 use Org\Mxchange\CoreFramework\Request\Requestable;
13 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
14 use Org\Mxchange\CoreFramework\Response\Responseable;
17 * A command for the login area (member/gamer area)
19 * @author Roland Haeder <webmaster@shipsimu.org>
21 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
22 * @license GNU GPL 3.0 or any newer version
23 * @link http://www.shipsimu.org
25 * This program is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
42 private $actionName = '';
45 * Protected constructor
49 protected function __construct () {
50 // Call parent constructor
51 parent::__construct(__CLASS__);
55 * Creates an instance of this class
57 * @param $resolverInstance An instance of a command resolver class
58 * @return $commandInstance An instance a prepared command class
60 public static final function createHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
62 $commandInstance = new HtmlLoginAreaCommand();
64 // Set the application instance
65 $commandInstance->setResolverInstance($resolverInstance);
67 // Load general data like user status and such
68 $commandInstance->prepareCommand();
70 // Return the prepared instance
71 return $commandInstance;
75 * Prepares some general data which shall be displayed on every page
78 * @todo Add some stuff here: Some personal data, app/game related data
80 protected function prepareCommand () {
84 * Executes the given command with given request and response objects
86 * @param $requestInstance An instance of a class with an Requestable interface
87 * @param $responseInstance An instance of a class with an Responseable interface
90 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
91 // Get the action instance from registry
92 $actionInstance = GenericRegistry::getRegistry()->getInstance('action');
94 // Do we have an action here?
95 if ($actionInstance instanceof PerformableAction) {
96 // Execute the action (shall not output anything, see below why)
97 $actionInstance->execute($requestInstance, $responseInstance);
100 // Get the application instance
101 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
103 // Prepare a template instance
104 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
107 $templateInstance->assignConfigVariable('base_url');
109 // Assign all the application's data with template variables
110 $templateInstance->assignApplicationData($applicationInstance);
112 // Load the master template
113 $masterTemplate = $applicationInstance->buildMasterTemplateName();
115 // Load header template
116 $templateInstance->loadCodeTemplate('header');
118 // Compile and assign it with a variable
119 $templateInstance->compileTemplate();
120 $templateInstance->assignTemplateWithVariable('header', 'header');
122 // Load footer template
123 $templateInstance->loadCodeTemplate('footer');
125 // Compile and assign it with a variable
126 $templateInstance->compileTemplate();
127 $templateInstance->assignTemplateWithVariable('footer', 'footer');
129 // Load the matching template
130 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
132 // Assign the template with the master template as a content ... ;)
133 $templateInstance->compileTemplate();
134 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
136 // Load main template
137 $templateInstance->loadCodeTemplate('login_main');
139 // Assign the main template with the master template as a content ... ;)
140 $templateInstance->compileTemplate();
141 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
143 // Load the master template
144 $templateInstance->loadCodeTemplate($masterTemplate);
147 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
149 // Construct the menu in every command. We could do this in BaseCommand class. But this means
150 // *every* command has a navigation system and that is want we don't want.
151 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
154 $menuInstance->renderMenu();
156 // Transfer it to the template engine instance
157 $menuInstance->transferContentToTemplateEngine($templateInstance);
160 * ... and all variables. This should be merged together in a pattern
161 * to make things easier. A cache mechanism should be added between
162 * these two calls to cache compiled templates.
164 $templateInstance->compileVariables();
166 // Get the content back from the template engine and put it in response class
167 $templateInstance->transferToResponse($responseInstance);
171 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
173 * @param $controllerInstance A controller instance
174 * @param $requestInstance An instance of a class with an Requestable interface
177 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
178 // Default is no action
179 $actionInstance = NULL;
182 $registryInstance = GenericRegistry::getRegistry();
184 // Get our application instance from the registry
185 $applicationInstance = $registryInstance->getInstance('application');
187 // Default action is the one from configuration
188 $this->actionName = self::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
190 // Get "action" from request
191 $actReq = $requestInstance->getRequestElement('action');
193 // Do we have a "action" parameter set?
194 if ((is_string($actReq)) && (!empty($actReq))) {
195 // Then use it with prefix
196 $this->actionName = self::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
199 // Get application instance
200 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
203 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName, $applicationInstance);
205 // Resolve the action
206 $actionInstance = $actionResolver->resolveAction();
208 // Add more action-specific filters
209 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
211 // Remember this action in registry
212 GenericRegistry::getRegistry()->addInstance('action', $actionInstance);