3 namespace CoreFramework\Command\Login;
6 * A command for the login area (member/gamer area)
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
31 private $actionName = '';
34 * Protected constructor
38 protected function __construct () {
39 // Call parent constructor
40 parent::__construct(__CLASS__);
44 * Creates an instance of this class
46 * @param $resolverInstance An instance of a command resolver class
47 * @return $commandInstance An instance a prepared command class
49 public static final function createHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
51 $commandInstance = new HtmlLoginAreaCommand();
53 // Set the application instance
54 $commandInstance->setResolverInstance($resolverInstance);
56 // Load general data like user status and such
57 $commandInstance->prepareCommand();
59 // Return the prepared instance
60 return $commandInstance;
64 * Prepares some general data which shall be displayed on every page
67 * @todo Add some stuff here: Some personal data, app/game related data
69 protected function prepareCommand () {
73 * Executes the given command with given request and response objects
75 * @param $requestInstance An instance of a class with an Requestable interface
76 * @param $responseInstance An instance of a class with an Responseable interface
79 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
80 // Get the action instance from registry
81 $actionInstance = Registry::getRegistry()->getInstance('action');
83 // Do we have an action here?
84 if ($actionInstance instanceof PerformableAction) {
85 // Execute the action (shall not output anything, see below why)
86 $actionInstance->execute($requestInstance, $responseInstance);
89 // Get the application instance
90 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
92 // Prepare a template instance
93 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
96 $templateInstance->assignConfigVariable('base_url');
98 // Assign all the application's data with template variables
99 $templateInstance->assignApplicationData($applicationInstance);
101 // Load the master template
102 $masterTemplate = $applicationInstance->buildMasterTemplateName();
104 // Load header template
105 $templateInstance->loadCodeTemplate('header');
107 // Compile and assign it with a variable
108 $templateInstance->compileTemplate();
109 $templateInstance->assignTemplateWithVariable('header', 'header');
111 // Load footer template
112 $templateInstance->loadCodeTemplate('footer');
114 // Compile and assign it with a variable
115 $templateInstance->compileTemplate();
116 $templateInstance->assignTemplateWithVariable('footer', 'footer');
118 // Load the matching template
119 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
121 // Assign the template with the master template as a content ... ;)
122 $templateInstance->compileTemplate();
123 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
125 // Load main template
126 $templateInstance->loadCodeTemplate('login_main');
128 // Assign the main template with the master template as a content ... ;)
129 $templateInstance->compileTemplate();
130 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
132 // Load the master template
133 $templateInstance->loadCodeTemplate($masterTemplate);
136 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
138 // Construct the menu in every command. We could do this in BaseCommand class. But this means
139 // *every* command has a navigation system and that is want we don't want.
140 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
143 $menuInstance->renderMenu();
145 // Transfer it to the template engine instance
146 $menuInstance->transferContentToTemplateEngine($templateInstance);
149 * ... and all variables. This should be merged together in a pattern
150 * to make things easier. A cache mechanism should be added between
151 * these two calls to cache compiled templates.
153 $templateInstance->compileVariables();
155 // Get the content back from the template engine and put it in response class
156 $templateInstance->transferToResponse($responseInstance);
160 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
162 * @param $controllerInstance A controller instance
163 * @param $requestInstance An instance of a class with an Requestable interface
166 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
167 // Default is no action
168 $actionInstance = NULL;
171 $registryInstance = Registry::getRegistry();
173 // Get our application instance from the registry
174 $applicationInstance = $registryInstance->getInstance('application');
176 // Default action is the one from configuration
177 $this->actionName = self::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
179 // Get "action" from request
180 $actReq = $requestInstance->getRequestElement('action');
182 // Do we have a "action" parameter set?
183 if ((is_string($actReq)) && (!empty($actReq))) {
184 // Then use it with prefix
185 $this->actionName = self::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
188 // Get application instance
189 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
192 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName, $applicationInstance);
194 // Resolve the action
195 $actionInstance = $actionResolver->resolveAction();
197 // Add more action-specific filters
198 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
200 // Remember this action in registry
201 Registry::getRegistry()->addInstance('action', $actionInstance);