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