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\Registry;
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 <<<<<<< HEAD:framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
25 >>>>>>> Some updates::inc/main/classes/commands/html/class_HtmlLoginAreaCommand.php
26 * @license GNU GPL 3.0 or any newer version
27 * @link http://www.shipsimu.org
29 * This program is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program. If not, see <http://www.gnu.org/licenses/>.
42 class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
46 private $actionName = '';
49 * Protected constructor
53 protected function __construct () {
54 // Call parent constructor
55 parent::__construct(__CLASS__);
59 * Creates an instance of this class
61 * @param $resolverInstance An instance of a command resolver class
62 * @return $commandInstance An instance a prepared command class
64 public static final function createHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
66 $commandInstance = new HtmlLoginAreaCommand();
68 // Set the application instance
69 $commandInstance->setResolverInstance($resolverInstance);
71 // Load general data like user status and such
72 $commandInstance->prepareCommand();
74 // Return the prepared instance
75 return $commandInstance;
79 * Prepares some general data which shall be displayed on every page
82 * @todo Add some stuff here: Some personal data, app/game related data
84 protected function prepareCommand () {
88 * Executes the given command with given request and response objects
90 * @param $requestInstance An instance of a class with an Requestable interface
91 * @param $responseInstance An instance of a class with an Responseable interface
94 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
95 // Get the action instance from registry
96 $actionInstance = Registry::getRegistry()->getInstance('action');
98 // Do we have an action here?
99 if ($actionInstance instanceof PerformableAction) {
100 // Execute the action (shall not output anything, see below why)
101 $actionInstance->execute($requestInstance, $responseInstance);
104 // Get the application instance
105 $applicationInstance = Registry::getRegistry()->getInstance('app');
107 // Prepare a template instance
108 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
111 $templateInstance->assignConfigVariable('base_url');
113 // Assign all the application's data with template variables
114 $templateInstance->assignApplicationData($applicationInstance);
116 // Load the master template
117 $masterTemplate = $applicationInstance->buildMasterTemplateName();
119 // Load header template
120 $templateInstance->loadCodeTemplate('header');
122 // Compile and assign it with a variable
123 $templateInstance->compileTemplate();
124 $templateInstance->assignTemplateWithVariable('header', 'header');
126 // Load footer template
127 $templateInstance->loadCodeTemplate('footer');
129 // Compile and assign it with a variable
130 $templateInstance->compileTemplate();
131 $templateInstance->assignTemplateWithVariable('footer', 'footer');
133 // Load the matching template
134 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
136 // Assign the template with the master template as a content ... ;)
137 $templateInstance->compileTemplate();
138 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
140 // Load main template
141 $templateInstance->loadCodeTemplate('login_main');
143 // Assign the main template with the master template as a content ... ;)
144 $templateInstance->compileTemplate();
145 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
147 // Load the master template
148 $templateInstance->loadCodeTemplate($masterTemplate);
151 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
153 // Construct the menu in every command. We could do this in BaseCommand class. But this means
154 // *every* command has a navigation system and that is want we don't want.
155 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
158 $menuInstance->renderMenu();
160 // Transfer it to the template engine instance
161 $menuInstance->transferContentToTemplateEngine($templateInstance);
164 * ... and all variables. This should be merged together in a pattern
165 * to make things easier. A cache mechanism should be added between
166 * these two calls to cache compiled templates.
168 $templateInstance->compileVariables();
170 // Get the content back from the template engine and put it in response class
171 $templateInstance->transferToResponse($responseInstance);
175 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
177 * @param $controllerInstance A controller instance
178 * @param $requestInstance An instance of a class with an Requestable interface
181 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
182 // Default is no action
183 $actionInstance = NULL;
186 $registryInstance = Registry::getRegistry();
188 // Get our application instance from the registry
189 $applicationInstance = $registryInstance->getInstance('application');
191 // Default action is the one from configuration
192 $this->actionName = self::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
194 // Get "action" from request
195 $actReq = $requestInstance->getRequestElement('action');
197 // Do we have a "action" parameter set?
198 if ((is_string($actReq)) && (!empty($actReq))) {
199 // Then use it with prefix
200 $this->actionName = self::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
203 // Get application instance
204 $applicationInstance = Registry::getRegistry()->getInstance('app');
207 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName, $applicationInstance);
209 // Resolve the action
210 $actionInstance = $actionResolver->resolveAction();
212 // Add more action-specific filters
213 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
215 // Remember this action in registry
216 Registry::getRegistry()->addInstance('action', $actionInstance);