3 * A command for a failed startup request. This may happen when the user
4 * "knows" the correct URL but government refuses to pay.
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu Developer Team
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class WebGovernmentFailedStartupCommand extends BaseCommand implements Commandable {
27 * Protected constructor
31 protected function __construct () {
32 // Call parent constructor
33 parent::__construct(__CLASS__);
37 * Creates an instance of this class
39 * @param $resolverInstance An instance of a command resolver class
40 * @return $commandInstance An instance a prepared command class
42 public final static function createWebGovernmentFailedStartupCommand (CommandResolver $resolverInstance) {
44 $commandInstance = new WebGovernmentFailedStartupCommand();
46 // Set the application instance
47 $commandInstance->setResolverInstance($resolverInstance);
49 // Return the prepared instance
50 return $commandInstance;
54 * Executes the given command with given request and response objects
56 * @param $requestInstance An instance of a class with an Requestable interface
57 * @param $responseInstance An instance of a class with an Responseable interface
61 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
62 // Get the action instance from registry
63 $actionInstance = Registry::getRegistry()->getInstance('action');
65 // Do we have an action here?
66 if ($actionInstance instanceof PerformableAction) {
67 // Execute the action (shall not output anything, see below why)
68 $actionInstance->execute($requestInstance, $responseInstance);
71 // Get the application instance
72 $appInstance = $this->getResolverInstance()->getApplicationInstance();
74 // Prepare a template instance
75 $templateInstance = $this->prepareTemplateInstance($appInstance);
78 $templateInstance->assignConfigVariable('base_url');
80 // Assign all the application's data with template variables
81 $templateInstance->assignApplicationData($appInstance);
83 // Load the master template
84 $masterTemplate = $appInstance->buildMasterTemplateName();
86 // Load header template
87 $templateInstance->loadCodeTemplate('header');
89 // Compile and assign it with a variable
90 $templateInstance->compileTemplate();
91 $templateInstance->assignTemplateWithVariable('header', 'header');
93 // Load footer template
94 $templateInstance->loadCodeTemplate('footer');
96 // Compile and assign it with a variable
97 $templateInstance->compileTemplate();
98 $templateInstance->assignTemplateWithVariable('footer', 'footer');
100 // Load main template
101 $templateInstance->loadCodeTemplate('government_failed_main');
103 // Assign the main template with the master template as a content ... ;)
104 $templateInstance->compileTemplate();
105 $templateInstance->assignTemplateWithVariable('government_failed_main', 'content');
107 // Load the master template
108 $templateInstance->loadCodeTemplate($masterTemplate);
111 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage($requestInstance->getRequestElement('page') . '_' . $requestInstance->getRequestElement('failed') . '_title'));
113 // Construct the menu in every command. We could do this in BaseCommand class. But this means
114 // *every* command has a navigation system and that is want we don't want.
115 $menuInstance = ObjectFactory::createObjectByConfiguredName('government_failed_area_menu_class', array($appInstance));
117 // ... and all variables. This should be merged together in a pattern
118 // to make things easier. A cache mechanism should be added between
119 // these two calls to cache compiled templates.
120 $templateInstance->compileVariables();
122 // Get the content back from the template engine and put it in response class
123 $templateInstance->transferToResponse($responseInstance);
127 * Adds extra filters to the given controller instance
129 * @param $controllerInstance A controller instance
130 * @param $requestInstance An instance of a class with an Requestable interface
132 * @todo Maybe we need some filters here?
134 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {