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@ship-simu.org>
25 * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 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 $thisInstance = null;
67 protected function __construct () {
68 // Call parent constructor
69 parent::__construct(__CLASS__);
72 $this->removeSystemArray();
73 $this->removeNumberFormaters();
77 * Getter for an instance of this class
79 * @return $thisInstance An instance of this class
81 public final static function getInstance () {
82 // Is the instance there?
83 if (is_null(self::$thisInstance)) {
84 self::$thisInstance = new ApplicationHelper();
87 // Return the instance
88 return self::$thisInstance;
92 * Getter for the version number
94 * @return $appVersion The application's version number
96 public final function getAppVersion () {
97 return $this->appVersion;
100 * Setter for the version number
102 * @param $appVersion The application's version number
105 public final function setAppVersion ($appVersion) {
107 $this->appVersion = (string) $appVersion;
111 * Getter for human-readable name
113 * @return $appName The application's human-readable name
115 public final function getAppName () {
116 return $this->appName;
120 * Setter for human-readable name
122 * @param $appName The application's human-readable name
125 public final function setAppName ($appName) {
127 $this->appName = (string) $appName;;
131 * Getter for short uni*-like name
133 * @return $shortName The application's short uni*-like name
135 public final function getAppShortName () {
136 return $this->shortName;
140 * Setter for short uni*-like name
142 * @param $shortName The application's short uni*-like name
145 public final function setAppShortName ($shortName) {
147 $this->shortName = (string) $shortName;
151 * Launches the hub system
155 public final function entryPoint () {
156 // ----------------------------- Init phase ---------------------------
157 // The default node-mode is from our configuration
158 $nodeMode = $this->getConfigInstance()->readConfig('node_mode');
160 // Prepare a ConsoleRequest class to catch all parameters
161 $requestInstance = ObjectFactory::createObjectByName('ConsoleRequest');
163 // Is the node 'mode' parameter set?
164 if ($requestInstance->isRequestElementSet('mode')) {
165 // Then use this which overrides the config entry temporarily
166 $nodeMode = $requestInstance->getRequestElement('mode');
168 // Set it for easier re-usage
169 $requestInstance->setRequestElement('mode', $nodeMode);
172 // Now convert the node-mode in a class name
173 $className = 'Hub' . $this->convertToClassName($nodeMode) . 'Node';
175 // And try to instance it
178 $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
180 // Set the app instance
181 $nodeInstance->setApplicationInstance($this);
182 } catch (ClassNotFoundException $e) {
183 // This exception means, the node mode is invalid.
184 // @TODO Can we rewrite this to app_die() ?
185 die('Node mode ' . $nodeMode . ' is invalid.' . "\n");
188 // ----------------------- Output teaser lines ------------------------
189 // Output some introducing lines to the console. This should be later
190 // be switched off if this is a productive release because it would be
191 // only visible to the logfile.
192 $nodeInstance->outputConsoleTeaser();
194 // ----------------------- Bootstrapping phase ------------------------
195 // Try to bootstrap the node and pass the request instance to it for
196 // extra arguments which mostly override config entries or enable special
197 // features within the hub (none is ready at this development stage)
198 $this->getDebugInstance()->output('BOOTSTRAP: Beginning with bootstrap...');
199 $nodeInstance->doBootstrapping();
200 $this->getDebugInstance()->output('BOOTSTRAP: Bootstrap finished.');
202 // ----------------------- Init all query queues ----------------------
203 // After the bootstrap is done we need to initialize the queues which
204 // will help us to communicate between the "tasks" a hub needs to do.
205 $nodeInstance->initQueues();
207 // -------------------------- Hub activation --------------------------
208 // Activates the hub by doing some final preparation steps and setting
209 // the attribute $hubIsActive to true
210 $nodeInstance->activateHub();
212 // ----------------------------- Main loop ----------------------------
213 // This is the main loop. Queried calls should come back here very fast
214 // so the whole application runs on nice speed. This while-loop goes
215 // until the hub is no longer active.
216 while ($nodeInstance->isHubActive()) {
219 // -------------------------- Shutdown phase --------------------------
220 // Shutting down the hub by saying "good bye" to all connected clients
221 // and other hubs, flushing all queues and caches.
222 $nodeInstance->doShutdown();
226 * Handle the indexed array of fatal messages and puts them out in an
229 * @param $messageList An array of fatal messages
232 public function handleFatalMessages (array $messageList) {
233 // Walk through all messages
234 foreach ($messageList as $message) {
235 die("MSG:" . $message);
240 * Builds the master template's name
242 * @return $masterTemplateName Name of the master template
244 public function buildMasterTemplateName () {