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