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@mxchange.org>
12 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
13 * @license GNU GPL 3.0 or any newer version
14 * @link http://www.ship-simu.org
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 class ApplicationEntryPoint {
31 * The instances we want to remove after all is done
35 private static $instances = array (
36 'cfg', // The configuration system
37 'loader', // The class loader system
38 'debug', // Debug output
39 'db', // Database layer
40 'io', // Base I/O system (local file [or network])
41 'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
42 'lang', // Language sub-system
43 'app', // The ApplicationHelper instance
47 * The application's emergency exit
49 * @param $message The optional message we shall output on exit
52 public static function app_die ($message = "") {
53 // Is this method already called?
54 if (defined('EMERGENCY_EXIT_CALLED')) {
55 // Then output the text directly
59 // This method shall not be called twice
60 define('EMERGENCY_EXIT_CALLED', true);
63 if (empty($message)) {
64 // No message provided
65 $message = "No message provided!";
69 $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
70 $lang = LanguageSystem::getInstance();
71 $io = FileIOHandler::getInstance();
73 // Is the template engine loaded?
74 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
75 // Use the template engine for putting out (nicer look) the message
77 $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", \$lang, \$io);",
78 FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
79 FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
81 FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
84 } catch (BasePathIsEmptyException $e) {
85 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
88 } catch (InvalidBasePathStringException $e) {
89 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
92 } catch (BasePathIsNoDirectoryException $e) {
93 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
96 } catch (BasePathReadProtectedException $e) {
97 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
102 // Backtrace holen und aufbereiten
103 $backtraceArray = debug_backtrace();
105 foreach ($backtraceArray as $key=>$trace) {
106 if (!isset($trace['file'])) $trace['file'] = __FILE__;
107 if (!isset($trace['line'])) $trace['line'] = 5;
108 if (!isset($trace['args'])) $trace['args'] = array();
109 $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
113 $tplEngine->assignVariable("message", $message);
114 $tplEngine->assignVariable("backtrace", $backtrace);
117 $tplEngine->loadCodeTemplate("emergency_exit");
119 // Compile the template
120 $tplEngine->compileTemplate();
122 // Compile all variables
123 $tplEngine->compileVariables();
126 $tplEngine->output();
131 // Output message and die
132 die(sprintf("[Main:] Emergency exit reached: <span class=\"emergency_span\">%s</span>",
139 * The application's main entry point. This class isolates some local
140 * variables which shall not become visible to outside because of security
141 * concerns. We are doing this here to "emulate" the well-known entry
146 public static function main () {
147 // Some non-global common arrays we need...
151 require(dirname(__FILE__) . "/inc/config.php");
153 // Load all include files
154 require(PATH . "inc/includes.php");
156 // Load all framework classes
157 require(PATH . "inc/classes.php");
159 // Include the application selector
160 require(PATH . "inc/selector.php");
166 // Do not remove the following line:
167 ApplicationEntryPoint::main();