3 * A class holding general data about the application and some methods for
4 * the management including the entry point.
10 * You need to create a folder in the folder "application" named "my_app"
11 * (without the quotes) and create a include file called
12 * class_ApplicationHelper.php. You have to write the same class for your
13 * application and implement the same interface called ManageableApplication
14 * because this class include file will be searched for.
16 * It is good when you avoid more GET parameters to keep URLs short and sweet.
17 * But sometimes you need some GET paramerers e.g. for your imprint or info page
18 * or other linked pages which you have to create and state some informations.
20 * Please remember that this include file is being loaded *before* the class
21 * loader is loading classes from "exceptions", "interfaces" and "main"!
23 * @author Roland Haeder <webmaster@shipsimu.org>
25 * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
26 * @license GNU GPL 3.0 or any newer version
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 ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
43 * The version number of this application
45 private $appVersion = '';
48 * The human-readable name for this application
50 private $appName = '';
53 * The short uni*-like name for this application
55 private $shortName = '';
58 * An instance of this class
60 private static $selfInstance = NULL;
67 protected function __construct () {
68 // Call parent constructor
69 parent::__construct(__CLASS__);
73 * Getter for an instance of this class
75 * @return $selfInstance An instance of this class
77 public static final function getSelfInstance () {
78 // Is the instance there?
79 if (is_null(self::$selfInstance)) {
80 self::$selfInstance = new ApplicationHelper();
83 // Return the instance
84 return self::$selfInstance;
88 * Getter for the version number
90 * @return $appVersion The application's version number
92 public final function getAppVersion () {
93 return $this->appVersion;
96 * Setter for the version number
98 * @param $appVersion The application's version number
101 public final function setAppVersion ($appVersion) {
103 $this->appVersion = (string) $appVersion;
107 * Getter for human-readable name
109 * @return $appName The application's human-readable name
111 public final function getAppName () {
112 return $this->appName;
116 * Setter for human-readable name
118 * @param $appName The application's human-readable name
121 public final function setAppName ($appName) {
123 $this->appName = (string) $appName;;
127 * Getter for short uni*-like name
129 * @return $shortName The application's short uni*-like name
131 public final function getAppShortName () {
132 return $this->shortName;
136 * Setter for short uni*-like name
138 * @param $shortName The application's short uni*-like name
141 public final function setAppShortName ($shortName) {
143 $this->shortName = (string) $shortName;
147 * Launches the hub system
151 public final function entryPoint () {
152 // Set this application in registry
153 Registry::getRegistry()->addInstance('app', $this);
155 // Is no external address set?
156 if ($this->getConfigInstance()->getConfigEntry('external_address') == '') {
157 // Determine external address
158 $this->getConfigInstance()->setConfigEntry('external_address', HubTools::determineOwnExternalAddress());
161 // Default response is console
162 $response = self::getResponseTypeFromSystem();
163 $responseType = self::getResponseTypeFromSystem();
165 // Create a new request object
166 $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
168 // Remember request instance here
169 $this->setRequestInstance($requestInstance);
171 // Do we have another response?
172 if ($requestInstance->isRequestElementSet('request')) {
174 $response = strtolower($requestInstance->getRequestElement('request'));
175 $responseType = $response;
178 // ... and a new response object
179 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
180 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
182 // Remember response instance here
183 $this->setResponseInstance($responseInstance);
185 // Get the parameter from the request
186 $commandName = $requestInstance->getRequestElement('command');
188 // If it is null then get default command
189 if (is_null($commandName)) {
190 // Get default command
191 $commandName = $responseInstance->determineDefaultCommand();
194 $requestInstance->setRequestElement('command', $commandName);
197 // Is the responseType 'html' ?
198 if ($responseType == 'html') {
199 // The language system is needed for this
200 $languageInstance = ObjectFactory::createObjectByConfiguredName('language_system_class');
203 $this->setLanguageInstance($languageInstance);
206 // Get a controller resolver
207 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
208 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
210 // Get a controller instance as well
211 $this->setControllerInstance($resolverInstance->resolveController());
213 // Launch the hub main routine here
214 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
216 // Only for console requests as this is the actual daemon
217 if ($responseType == 'console') {
218 // -------------------------- Shutdown phase --------------------------
219 // Shutting down the hub by saying "good bye" to all connected peers
220 // and other hubs, flushing all queues and caches.
221 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
222 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
223 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
228 * Assigns extra application-depending data
230 * @param $templateInstance An instance of a CompileableTemplate
232 * @todo Nothing to add?
234 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
238 * Handle the indexed array of fatal messages and puts them out in an
241 * @param $messageList An array of fatal messages
244 public function handleFatalMessages (array $messageList) {
245 // Walk through all messages
246 foreach ($messageList as $message) {
247 exit(__METHOD__ . ':MSG:' . $message);
252 * Builds the master template's name
254 * @return $masterTemplateName Name of the master template
256 public function buildMasterTemplateName () {