3 namespace Org\Mxchange\CoreFramework\Command\Login;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Action\PerformableAction;
7 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
8 use Org\Mxchange\CoreFramework\Command\BaseCommand;
9 use Org\Mxchange\CoreFramework\Command\Commandable;
10 use Org\Mxchange\CoreFramework\Controller\Controller;
11 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
12 use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
13 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
14 use Org\Mxchange\CoreFramework\Request\Requestable;
15 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
16 use Org\Mxchange\CoreFramework\Response\Responseable;
17 use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
20 * A command for the login area (member/gamer area)
22 * @author Roland Haeder <webmaster@shipsimu.org>
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
25 * @license GNU GPL 3.0 or any newer version
26 * @link http://www.shipsimu.org
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
41 class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
45 private $actionName = '';
48 * Protected constructor
52 private function __construct () {
53 // Call parent constructor
54 parent::__construct(__CLASS__);
58 * Creates an instance of this class
60 * @param $resolverInstance An instance of a command resolver class
61 * @return $commandInstance An instance a prepared command class
63 public static final function createHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
65 $commandInstance = new HtmlLoginAreaCommand();
67 // Set the application instance
68 $commandInstance->setResolverInstance($resolverInstance);
70 // Load general data like user status and such
71 $commandInstance->prepareCommand();
73 // Return the prepared instance
74 return $commandInstance;
78 * Prepares some general data which shall be displayed on every page
81 * @todo Add some stuff here: Some personal data, app/game related data
83 protected function prepareCommand () {
87 * Executes the given command with given request and response objects
89 * @param $requestInstance An instance of a class with an Requestable interface
90 * @param $responseInstance An instance of a class with an Responseable interface
93 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
94 // Get the action instance from registry
95 $actionInstance = GenericRegistry::getRegistry()->getInstance('action');
97 // Do we have an action here?
98 if ($actionInstance instanceof PerformableAction) {
99 // Execute the action (shall not output anything, see below why)
100 $actionInstance->execute($requestInstance, $responseInstance);
103 // Get the application instance
104 $applicationInstance = ApplicationHelper::getSelfInstance();
107 $this->getTemplateInstance()->assignConfigVariable('base_url');
109 // Assign all the application's data with template variables
110 $this->getTemplateInstance()->assignApplicationData();
112 // Load the master template
113 $masterTemplate = $applicationInstance->buildMasterTemplateName();
115 // Load header template
116 $this->getTemplateInstance()->loadCodeTemplate('header');
118 // Compile and assign it with a variable
119 $this->getTemplateInstance()->compileTemplate();
120 $this->getTemplateInstance()->assignTemplateWithVariable('header', 'header');
122 // Load footer template
123 $this->getTemplateInstance()->loadCodeTemplate('footer');
125 // Compile and assign it with a variable
126 $this->getTemplateInstance()->compileTemplate();
127 $this->getTemplateInstance()->assignTemplateWithVariable('footer', 'footer');
129 // Load the matching template
130 $this->getTemplateInstance()->loadCodeTemplate('action_' . $this->actionName);
132 // Assign the template with the master template as a content ... ;)
133 $this->getTemplateInstance()->compileTemplate();
134 $this->getTemplateInstance()->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
136 // Load main template
137 $this->getTemplateInstance()->loadCodeTemplate('login_main');
139 // Assign the main template with the master template as a content ... ;)
140 $this->getTemplateInstance()->compileTemplate();
141 $this->getTemplateInstance()->assignTemplateWithVariable('login_main', 'main_content');
143 // Load the master template
144 $this->getTemplateInstance()->loadCodeTemplate($masterTemplate);
147 $this->getTemplateInstance()->assignVariable('title', FrameworkBootstrap::getLanguageInstance()->getMessage($this->actionName . '_title'));
149 // Construct the menu in every command. We could do this in BaseCommand class. But this means
150 // *every* command has a navigation system and that is want we don't want.
151 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class');
154 $menuInstance->renderMenu();
156 // Transfer it to the template engine instance
157 $menuInstance->transferContentToTemplateEngine($this->getTemplateInstance());
160 * ... and all variables. This should be merged together in a pattern
161 * to make things easier. A cache mechanism should be added between
162 * these two calls to cache compiled templates.
164 $this->getTemplateInstance()->compileVariables();
166 // Get the content back from the template engine and put it in response class
167 $this->getTemplateInstance()->transferToResponse($responseInstance);
171 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
173 * @param $controllerInstance A controller instance
174 * @param $requestInstance An instance of a class with an Requestable interface
177 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
178 // Get our application instance from the registry
179 $applicationInstance = ApplicationHelper::getSelfInstance();
181 // Default action is the one from configuration
182 $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('login_default_action');
184 // Get "action" from request
185 $actReq = $requestInstance->getRequestElement('action');
187 // Do we have a "action" parameter set?
188 if (!empty($actReq)) {
189 // Then use it with prefix
190 $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
194 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName);
196 // Resolve the action
197 $actionInstance = $actionResolver->resolveAction();
199 // Add more action-specific filters
200 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
202 // Remember this action in registry
203 GenericRegistry::getRegistry()->addInstance('action', $actionInstance);