CSS classes formed to ids and command LocalHome finished
[shipsimu.git] / index.php
1 <?php
2 /**
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
6  * local variables.
7  *
8  * But good little boys and girls would always initialize their variables... ;-)
9  *
10  * @author              Roland Haeder <webmaster@mxchange.org>
11  * @version             0.3.0
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
15  *
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.
20  *
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.
25  *
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/>.
28  */
29 class ApplicationEntryPoint {
30         /**
31          * The instances we want to remove after all is done
32          *
33          * @return      void
34          */
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
44         );
45
46         /**
47          * The application's emergency exit
48          *
49          * @param               $message        The optional message we shall output on exit
50          * @return      void
51          */
52         public static function app_die ($message = "") {
53                 // Is a message set?
54                 if (empty($message)) {
55                         // No message provided
56                         $message = "No message provided!";
57                 }
58
59                 // Get some instances
60                 $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
61                 $lang = LanguageSystem::getInstance();
62                 $io = FileIOHandler::getInstance();
63
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
67                         try {
68                                 $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", \$lang, \$io);",
69                                         FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
70                                         FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
71                                         PATH,
72                                         FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
73                                 );
74                                 eval($eval);
75                         } catch (BasePathIsEmptyException $e) {
76                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
77                                         $e->getMessage()
78                                 ));
79                         } catch (InvalidBasePathStringException $e) {
80                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
81                                         $e->getMessage()
82                                 ));
83                         } catch (BasePathIsNoDirectoryException $e) {
84                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
85                                         $e->getMessage()
86                                 ));
87                         } catch (BasePathReadProtectedException $e) {
88                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
89                                         $e->getMessage()
90                                 ));
91                         }
92
93                         // Assign message
94                         $tplEngine->assignVariable("message", $message);
95
96                         // Load the template
97                         $tplEngine->loadCodeTemplate("emergency_exit");
98
99                         // Compile the template
100                         $tplEngine->compileTemplate();
101
102                         // Compile all variables
103                         $tplEngine->compileVariables();
104
105                         // Output all
106                         $tplEngine->output();
107
108                         // Good bye...
109                         exit();
110                 } else {
111                         // Output message and die
112                         die(sprintf("[Main:] Emergency exit reached: <strong>%s</strong>",
113                                 $message
114                         ));
115                 }
116         }
117
118         /**
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
122          * point in Java(tm).
123          *
124          * @return      void
125          */
126         public static function main () {
127                 // Some non-global common arrays we need...
128                 global $_SERVER;
129
130                 // Load config file
131                 require(dirname(__FILE__) . "/inc/config.php");
132
133                 // Load all include files
134                 require(PATH . "inc/includes.php");
135
136                 // Load all framework classes
137                 require(PATH . "inc/classes.php");
138
139                 // Include the application selector
140                 require(PATH . "inc/selector.php");
141
142         } // END - main()
143
144 } // END - class
145
146 // Do not remove the following line:
147 ApplicationEntryPoint::main();
148
149 // [EOF]
150 ?>