(no commit message)
[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@ship-simu.org>
11  * @version             0.0
12  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
13  * @license             GNU GPL 3.0 or any newer version
14  *
15  * This program is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  */
28 class ApplicationEntryPoint {
29         /**
30          * The instances we want to remove after all is done
31          *
32          * @return      void
33          */
34         private static $instances = array (
35                 'cfg',  // The configuration system
36                 'loader',       // The class loader system
37                 'debug',  // Debug output
38                 'db',     // Database layer
39                 'io',     // Base I/O system (local file [or network])
40                 'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
41                 'lang',   // Language sub-system
42                 'app',    // The ApplicationHelper instance
43         );
44
45         /**
46          * The application's emergency exit
47          *
48          * @param               $message        The optional message we shall output on exit
49          * @return      void
50          */
51         public static function app_die ($message = "") {
52                 // Is a message set?
53                 if (empty($message)) {
54                         // No message provided
55                         $message = "No message provided!";
56                 }
57
58                 // Get some instances
59                 $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
60                 $lang = LanguageSystem::getInstance();
61                 $io = FileIOHandler::getInstance();
62
63                 // Is the template engine loaded?
64                 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
65                         // Use the template engine for putting out (nicer look) the message
66                         try {
67                                 $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", LanguageSystem::getInstance(), FileIOHandler::getInstance());",
68                                         FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
69                                         FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
70                                         PATH,
71                                         FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
72                                 );
73                                 eval($eval);
74                         } catch (BasePathIsEmptyException $e) {
75                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
76                                         $e->getMessage()
77                                 ));
78                         } catch (InvalidBasePathStringException $e) {
79                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
80                                         $e->getMessage()
81                                 ));
82                         } catch (BasePathIsNoDirectoryException $e) {
83                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
84                                         $e->getMessage()
85                                 ));
86                         } catch (BasePathReadProtectedException $e) {
87                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
88                                         $e->getMessage()
89                                 ));
90                         }
91
92                         // Assign message
93                         $tplEngine->assignVariable("message", $message);
94
95                         // Load the template
96                         $tplEngine->loadCodeTemplate("emergency_exit");
97
98                         // Compile the template
99                         $tplEngine->compileTemplate();
100
101                         // Compile all variables
102                         $tplEngine->compileVariables();
103
104                         // Output all
105                         $tplEngine->output();
106
107                         // Good bye...
108                         exit();
109                 } else {
110                         // Output message and die
111                         die(sprintf("[Main:] Emergency exit reached: <strong>%s</strong>",
112                                 $message
113                         ));
114                 }
115         }
116
117         /**
118          * The application's main entry point. This class isolates some local
119          * variables which shall not become visible to outside because of security
120          * concerns. We are doing this here to "emulate" the well-known entry
121          * point in Java(tm).
122          *
123          * @return      void
124          */
125         public static function main () {
126                 // Some non-global common arrays we need...
127                 global $_SERVER;
128
129                 // Load config file
130                 require(dirname(__FILE__) . "/inc/config.php");
131
132                 // Load all include files
133                 require(PATH . "inc/includes.php");
134
135                 // Load all framework classes
136                 require(PATH . "inc/classes.php");
137
138                 // Include the application selector
139                 require(PATH . "inc/selector.php");
140
141         } // END - main()
142
143 } // END - class
144
145 // Do not remove the following line:
146 ApplicationEntryPoint::main();
147
148 // [EOF]
149 ?>