2 //xdebug_start_trace();
4 * The main class with the entry point to the whole application. This class
5 * "emulates" Java(tm)'s entry point call. Additionally it covers local
6 * variables from outside access to prevent possible attacks on uninitialized
9 * But good little boys and girls would always initialize their variables... ;-)
11 * @author Roland Haeder <webmaster@mxchange.org>
13 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.ship-simu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class ApplicationEntryPoint {
32 * The instances we want to remove after all is done
36 private static $instances = array (
37 'cfg', // The configuration system
38 'loader', // The class loader system
39 'debug', // Debug output
40 'db', // Database layer
41 'io', // Base I/O system (local file [or network])
42 'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
43 'lang', // Language sub-system
44 'app', // The ApplicationHelper instance
48 * The application's emergency exit
50 * @param $message The optional message we shall output on exit
53 public static function app_die ($message = "") {
54 // Is this method already called?
55 if (defined('EMERGENCY_EXIT_CALLED')) {
56 // Then output the text directly
60 // This method shall not be called twice
61 define('EMERGENCY_EXIT_CALLED', true);
64 if (empty($message)) {
65 // No message provided
66 $message = "No message provided!";
70 $tpl = FrameworkConfiguration::getInstance()->readConfig('tpl_engine');
71 $lang = LanguageSystem::getInstance();
72 $io = FileIoHandler::getInstance();
74 // Is the template engine loaded?
75 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
76 // Use the template engine for putting out (nicer look) the message
78 $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", \$lang, \$io);",
79 FrameworkConfiguration::getInstance()->readConfig('tpl_engine'),
80 FrameworkConfiguration::getInstance()->readConfig('tpl_engine'),
82 FrameworkConfiguration::getInstance()->readConfig('tpl_base_path')
85 } catch (BasePathIsEmptyException $e) {
86 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
89 } catch (InvalidBasePathStringException $e) {
90 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
93 } catch (BasePathIsNoDirectoryException $e) {
94 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
97 } catch (BasePathReadProtectedException $e) {
98 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
103 // Backtrace holen und aufbereiten
104 $backtraceArray = debug_backtrace();
106 foreach ($backtraceArray as $key=>$trace) {
107 if (!isset($trace['file'])) $trace['file'] = __FILE__;
108 if (!isset($trace['line'])) $trace['line'] = 5;
109 if (!isset($trace['args'])) $trace['args'] = array();
110 $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
114 $tplEngine->assignVariable('message', $message);
115 $tplEngine->assignVariable('backtrace', $backtrace);
118 $tplEngine->loadCodeTemplate('emergency_exit');
120 // Compile the template
121 $tplEngine->compileTemplate();
123 // Compile all variables
124 $tplEngine->compileVariables();
127 $tplEngine->output();
132 // Output message and die
133 die(sprintf("[Main:] Emergency exit reached: <span class=\"emergency_span\">%s</span>",
140 * The application's main entry point. This class isolates some local
141 * variables which shall not become visible to outside because of security
142 * concerns. We are doing this here to "emulate" the well-known entry
147 public static function main () {
148 // Some non-global common arrays we need...
152 require(dirname(__FILE__) . '/inc/config.php');
154 // Load all include files
155 require(PATH . 'inc/includes.php');
157 // Load all framework classes
158 require(PATH . 'inc/classes.php');
160 // Include the application selector
161 require(PATH . 'inc/selector.php');
167 // Do not remove the following line:
168 ApplicationEntryPoint::main();