3 namespace CoreFramework\Command\Status;
6 * A command for Status page
8 * @author Roland Haeder <webmaster@shipsimu.org>
10 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
11 * @license GNU GPL 3.0 or any newer version
12 * @link http://www.shipsimu.org
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class HtmlStatusCommand extends BaseCommand implements Commandable {
29 * Protected constructor
33 protected function __construct () {
34 // Call parent constructor
35 parent::__construct(__CLASS__);
39 * Creates an instance of this class
41 * @param $resolverInstance An instance of a command resolver class
42 * @return $commandInstance An instance a prepared command class
44 public static final function createHtmlStatusCommand (CommandResolver $resolverInstance) {
46 $commandInstance = new HtmlStatusCommand();
48 // Set the application instance
49 $commandInstance->setResolverInstance($resolverInstance);
51 // Return the prepared instance
52 return $commandInstance;
56 * Executes the given command with given request and response objects
58 * @param $requestInstance An instance of a class with an Requestable interface
59 * @param $responseInstance An instance of a class with an Responseable interface
63 public function execute (Requestable $requestInstance, Responseable $responseInstance) {
64 // Get the application instance
65 $applicationInstance = $this->getResolverInstance()->getApplicationInstance();
67 // Prepare a template instance
68 $templateInstance = $this->prepareTemplateInstance($applicationInstance);
70 // Transfer application data
71 $templateInstance->assignApplicationData($applicationInstance);
73 // Load the master template
74 $masterTemplate = $applicationInstance->buildMasterTemplateName();
76 // Load header template
77 $templateInstance->loadCodeTemplate('header');
79 // Compile and assign it with a variable
80 $templateInstance->compileTemplate();
81 $templateInstance->assignTemplateWithVariable('header', 'header');
83 // Load footer template
84 $templateInstance->loadCodeTemplate('footer');
86 // Compile and assign it with a variable
87 $templateInstance->compileTemplate();
88 $templateInstance->assignTemplateWithVariable('footer', 'footer');
90 // Load the status template
91 $templateInstance->loadCodeTemplate('status');
93 // Assign the status template with the master template as a content ... ;)
94 $templateInstance->assignTemplateWithVariable('status', 'main_content');
96 // Load the master template
97 $templateInstance->loadCodeTemplate($masterTemplate);
100 $templateInstance->assignVariable('title', $this->getLanguageInstance()->getMessage('page_status_title'));
102 // Construct the menu in every command. We could do this in BaseCommand class. But this means
103 // *every* command has a navigation system and that is want we don't want.
104 $menuInstance = ObjectFactory::createObjectByConfiguredName('status_menu_class', array($applicationInstance));
107 $menuInstance->renderMenu();
109 // Transfer it to the template engine instance
110 $menuInstance->transferContentToTemplateEngine($templateInstance);
113 * ... and all variables. This should be merged together in a pattern
114 * to make things easier. A cache mechanism should be added between
115 * these two calls to cache compiled templates.
117 $templateInstance->compileVariables();
119 // Get the content back from the template engine and put it in response class
120 $templateInstance->transferToResponse($responseInstance);
124 * Adds extra filters to the given controller instance
126 * @param $controllerInstance A controller instance
127 * @param $requestInstance An instance of a class with an Requestable interface
130 public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) {