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.mxchange.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 = "") {
54 if (empty($message)) {
55 // No message provided
56 $message = "No message provided!";
60 $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
61 $lang = LanguageSystem::getInstance();
62 $io = FileIOHandler::getInstance();
64 // Is the template engine loaded?
65 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
66 // Use the template engine for putting out (nicer look) the message
68 $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", LanguageSystem::getInstance(), FileIOHandler::getInstance());",
69 FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
70 FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
72 FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
75 } catch (BasePathIsEmptyException $e) {
76 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
79 } catch (InvalidBasePathStringException $e) {
80 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
83 } catch (BasePathIsNoDirectoryException $e) {
84 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
87 } catch (BasePathReadProtectedException $e) {
88 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
94 $tplEngine->assignVariable("message", $message);
97 $tplEngine->loadCodeTemplate("emergency_exit");
99 // Compile the template
100 $tplEngine->compileTemplate();
102 // Compile all variables
103 $tplEngine->compileVariables();
106 $tplEngine->output();
111 // Output message and die
112 die(sprintf("[Main:] Emergency exit reached: <strong>%s</strong>",
119 * The application's main entry point. This class isolates some local
120 * variables which shall not become visible to outside because of security
121 * concerns. We are doing this here to "emulate" the well-known entry
126 public static function main () {
127 // Some non-global common arrays we need...
131 require(dirname(__FILE__) . "/inc/config.php");
133 // Load all include files
134 require(PATH . "inc/includes.php");
136 // Load all framework classes
137 require(PATH . "inc/classes.php");
139 // Include the application selector
140 require(PATH . "inc/selector.php");
146 // Do not remove the following line:
147 ApplicationEntryPoint::main();