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 // Get the template instance from our object factory
79 $tplEngine = ObjectFactory::createObjectByConfiguredName('tpl_engine', array(FrameworkConfiguration::getInstance()->readConfig('tpl_base_path'), $lang, $io));
80 } catch (BasePathIsEmptyException $e) {
81 die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
84 } catch (InvalidBasePathStringException $e) {
85 die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
88 } catch (BasePathIsNoDirectoryException $e) {
89 die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
92 } catch (BasePathReadProtectedException $e) {
93 die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
98 // Backtrace holen und aufbereiten
99 $backtraceArray = debug_backtrace();
101 foreach ($backtraceArray as $key=>$trace) {
102 if (!isset($trace['file'])) $trace['file'] = __FILE__;
103 if (!isset($trace['line'])) $trace['line'] = 5;
104 if (!isset($trace['args'])) $trace['args'] = array();
105 $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
109 $tplEngine->assignVariable('message', $message);
110 $tplEngine->assignVariable('backtrace', $backtrace);
111 $tplEngine->assignVariable('total_objects', ObjectFactory::getTotal());
114 $tplEngine->loadCodeTemplate('emergency_exit');
116 // Compile the template
117 $tplEngine->compileTemplate();
119 // Compile all variables
120 $tplEngine->compileVariables();
123 $tplEngine->output();
128 // Output message and die
129 die(sprintf("[Main:] Emergency exit reached: <span class=\"emergency_span\">%s</span>",
136 * The application's main entry point. This class isolates some local
137 * variables which shall not become visible to outside because of security
138 * concerns. We are doing this here to "emulate" the well-known entry
143 public static function main () {
144 // Some non-global common arrays we need...
148 require(dirname(__FILE__) . '/inc/config.php');
150 // Load all include files
151 require(PATH . 'inc/includes.php');
153 // Load all framework classes
154 require(PATH . 'inc/classes.php');
156 // Include the application selector
157 require(PATH . 'inc/selector.php');
163 // Do not remove the following line:
164 ApplicationEntryPoint::main();