3 namespace Org\Mxchange\CoreFramework\Command\Login;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Action\PerformableAction;
7 use Org\Mxchange\CoreFramework\Command\BaseCommand;
8 use Org\Mxchange\CoreFramework\Command\Commandable;
9 use Org\Mxchange\CoreFramework\Controller\Controller;
10 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
11 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
12 use Org\Mxchange\CoreFramework\Request\Requestable;
13 use Org\Mxchange\CoreFramework\Resolver\Command\CommandResolver;
14 use Org\Mxchange\CoreFramework\Response\Responseable;
15 use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
18 * A command for the login area (member/gamer area)
20 * @author Roland Haeder <webmaster@shipsimu.org>
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2019 Core Developer Team
23 * @license GNU GPL 3.0 or any newer version
24 * @link http://www.shipsimu.org
26 * This program is free software: you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation, either version 3 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program. If not, see <http://www.gnu.org/licenses/>.
39 class HtmlLoginAreaCommand extends BaseCommand implements Commandable {
43 private $actionName = '';
46 * Protected constructor
50 protected function __construct () {
51 // Call parent constructor
52 parent::__construct(__CLASS__);
56 * Creates an instance of this class
58 * @param $resolverInstance An instance of a command resolver class
59 * @return $commandInstance An instance a prepared command class
61 public static final function createHtmlLoginAreaCommand (CommandResolver $resolverInstance) {
63 $commandInstance = new HtmlLoginAreaCommand();
65 // Set the application instance
66 $commandInstance->setResolverInstance($resolverInstance);
68 // Load general data like user status and such
69 $commandInstance->prepareCommand();
71 // Return the prepared instance
72 return $commandInstance;
76 * Prepares some general data which shall be displayed on every page
79 * @todo Add some stuff here: Some personal data, app/game related data
81 protected function prepareCommand () {
85 * Executes the given command with given request and response objects
87 * @param $requestInstance An instance of a class with an Requestable interface
88 * @param $responseInstance An instance of a class with an Responseable interface
91 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
92 // Get the action instance from registry
93 $actionInstance = GenericRegistry::getRegistry()->getInstance('action');
95 // Do we have an action here?
96 if ($actionInstance instanceof PerformableAction) {
97 // Execute the action (shall not output anything, see below why)
98 $actionInstance->execute($requestInstance, $responseInstance);
101 // Get the application instance
102 $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
104 // Prepare a template instance
105 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
108 $templateInstance->assignConfigVariable('base_url');
110 // Assign all the application's data with template variables
111 $templateInstance->assignApplicationData();
113 // Load the master template
114 $masterTemplate = $applicationInstance->buildMasterTemplateName();
116 // Load header template
117 $templateInstance->loadCodeTemplate('header');
119 // Compile and assign it with a variable
120 $templateInstance->compileTemplate();
121 $templateInstance->assignTemplateWithVariable('header', 'header');
123 // Load footer template
124 $templateInstance->loadCodeTemplate('footer');
126 // Compile and assign it with a variable
127 $templateInstance->compileTemplate();
128 $templateInstance->assignTemplateWithVariable('footer', 'footer');
130 // Load the matching template
131 $templateInstance->loadCodeTemplate('action_' . $this->actionName);
133 // Assign the template with the master template as a content ... ;)
134 $templateInstance->compileTemplate();
135 $templateInstance->assignTemplateWithVariable('action_' . $this->actionName, 'login_content');
137 // Load main template
138 $templateInstance->loadCodeTemplate('login_main');
140 // Assign the main template with the master template as a content ... ;)
141 $templateInstance->compileTemplate();
142 $templateInstance->assignTemplateWithVariable('login_main', 'main_content');
144 // Load the master template
145 $templateInstance->loadCodeTemplate($masterTemplate);
148 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($this->actionName . '_title'));
150 // Construct the menu in every command. We could do this in BaseCommand class. But this means
151 // *every* command has a navigation system and that is want we don't want.
152 $menuInstance = ObjectFactory::createObjectByConfiguredName('login_area_menu_class', array($applicationInstance));
155 $menuInstance->renderMenu();
157 // Transfer it to the template engine instance
158 $menuInstance->transferContentToTemplateEngine($templateInstance);
161 * ... and all variables. This should be merged together in a pattern
162 * to make things easier. A cache mechanism should be added between
163 * these two calls to cache compiled templates.
165 $templateInstance->compileVariables();
167 // Get the content back from the template engine and put it in response class
168 $templateInstance->transferToResponse($responseInstance);
172 * Adds extra filters to the given controller instance. An corresponding action class must now exist!
174 * @param $controllerInstance A controller instance
175 * @param $requestInstance An instance of a class with an Requestable interface
178 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {
179 // Default is no action
180 $actionInstance = NULL;
183 $registryInstance = GenericRegistry::getRegistry();
185 // Get our application instance from the registry
186 $applicationInstance = $registryInstance->getInstance('application');
188 // Default action is the one from configuration
189 $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $this->getConfigInstance()->getConfigEntry('login_default_action');
191 // Get "action" from request
192 $actReq = $requestInstance->getRequestElement('action');
194 // Do we have a "action" parameter set?
195 if ((is_string($actReq)) && (!empty($actReq))) {
196 // Then use it with prefix
197 $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq;
201 $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName);
203 // Resolve the action
204 $actionInstance = $actionResolver->resolveAction();
206 // Add more action-specific filters
207 $actionInstance->addExtraFilters($controllerInstance, $requestInstance);
209 // Remember this action in registry
210 GenericRegistry::getRegistry()->addInstance('action', $actionInstance);