3 * The main class with the entry point to the whole application. This class
4 * "emulates" Java(tm)'s entry point call. Additionally it covers local
5 * variables from outside access to prevent possible attacks on uninitialized
8 * But good little boys and girls would always initialize their variables... ;-)
10 * @author Roland Haeder <webmaster@ship-simu.org>
12 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
13 * @license GNU GPL 3.0 or any newer version
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class ApplicationEntryPoint {
30 * The instances we want to remove after all is done
34 private static $instances = array (
35 'cfg', // The configuration system
36 'loader', // The class loader system
37 'debug', // Debug output
38 'db', // Database layer
39 'io', // Base I/O system (local file [or network])
40 'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
41 'lang', // Language sub-system
42 'app', // The ApplicationHelper instance
46 * The application's emergency exit
48 * @param $message The optional message we shall output on exit
51 public static function app_die ($message = "") {
53 if (empty($message)) {
54 // No message provided
55 $message = "No message provided!";
59 $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
60 $lang = LanguageSystem::getInstance();
61 $io = FileIOHandler::getInstance();
63 // Is the template engine loaded?
64 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
65 // Use the template engine for putting out (nicer look) the message
67 $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", LanguageSystem::getInstance(), FileIOHandler::getInstance());",
68 FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
69 FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
71 FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
74 } catch (BasePathIsEmptyException $e) {
75 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
78 } catch (InvalidBasePathStringException $e) {
79 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
82 } catch (BasePathIsNoDirectoryException $e) {
83 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
86 } catch (BasePathReadProtectedException $e) {
87 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
93 $tplEngine->assignVariable("message", $message);
96 $tplEngine->loadCodeTemplate("emergency_exit");
98 // Compile the template
99 $tplEngine->compileTemplate();
101 // Compile all variables
102 $tplEngine->compileVariables();
105 $tplEngine->output();
110 // Output message and die
111 die(sprintf("[Main:] Emergency exit reached: <strong>%s</strong>",
118 * The application's main entry point. This class isolates some local
119 * variables which shall not become visible to outside because of security
120 * concerns. We are doing this here to "emulate" the well-known entry
125 public static function main () {
126 // Some non-global common arrays we need...
130 require(dirname(__FILE__) . "/inc/config.php");
132 // Load all include files
133 require(PATH . "inc/includes.php");
135 // Load all framework classes
136 require(PATH . "inc/classes.php");
138 // Include the application selector
139 require(PATH . "inc/selector.php");
145 // Do not remove the following line:
146 ApplicationEntryPoint::main();