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