7dc259489720264dcc981729b95ec8b8fe3f5a26
[mailer.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 class ApplicationEntryPoint {
11         /**
12          * The instances we want to remove after all is done
13          *
14          * @return      void
15          */
16         private static $instances = array (
17                 'cfg',  // The configuration system
18                 'loader',       // The class loader system
19                 'debug',  // Debug output
20                 'db',     // Database layer
21                 'io',     // Base I/O system (local file [or network])
22                 'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
23                 'lang',   // Language sub-system
24                 'app',    // The ApplicationHelper instance
25         );
26
27         /**
28          * The application's emergency exit
29          *
30          * @param               $message        The optional message we shall output on exit
31          * @return      void
32          */
33         public static function app_die ($message = "") {
34                 // Is a message set?
35                 if (empty($message)) {
36                         // No message provided
37                         $message = "No message provided!";
38                 }
39
40                 // Get some instances
41                 $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
42                 $lang = LanguageSystem::getInstance();
43                 $io = FileIOHandler::getInstance();
44
45                 // Is the template engine loaded?
46                 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
47                         // Use the template engine for putting out (nicer look) the message
48                         try {
49                                 $eval = sprintf("$tplEngine = %s::create%s(\"%s%s\", LanguageSystem::getInstance(), FileIOHandler::getInstance());",
50                                         FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
51                                         FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
52                                         PATH,
53                                         FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
54                                 );
55                                 eval($eval);
56                         } catch (BasePathIsEmptyException $e) {
57                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
58                                         $e->getMessage()
59                                 ));
60                         } catch (InvalidBasePathStringException $e) {
61                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
62                                         $e->getMessage()
63                                 ));
64                         } catch (BasePathIsNoDirectoryException $e) {
65                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
66                                         $e->getMessage()
67                                 ));
68                         } catch (BasePathReadProtectedException $e) {
69                                 die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
70                                         $e->getMessage()
71                                 ));
72                         }
73
74                         // Assign message
75                         $tplEngine->assignVariable("message", $message);
76
77                         // Load the template
78                         $tplEngine->loadCodeTemplate("emergency_exit");
79
80                         // Compile the template
81                         $tplEngine->compileTemplate();
82
83                         // Compile all variables
84                         $tplEngine->compileVariables();
85
86                         // Output all
87                         $tplEngine->output();
88
89                         // Good bye...
90                         exit();
91                 } else {
92                         // Output message and die
93                         die(sprintf("[Main:] Emergency exit reached: <strong>%s</strong>",
94                                 $message
95                         ));
96                 }
97         }
98
99         /**
100          * The application's main entry point. This class isolates some local
101          * variables which shall not become visible to outside because of security
102          * concerns. We are doing this here to "emulate" the well-known entry
103          * point in Java(tm).
104          *
105          * @return      void
106          */
107         public static function main () {
108                 // Some non-global common arrays we need...
109                 global $_SERVER;
110
111                 // Load config file
112                 require(dirname(__FILE__) . "/inc/config.php");
113
114                 // Load all include files
115                 require(PATH . "inc/includes.php");
116
117                 // Load all framework classes
118                 require(PATH . "inc/classes.php");
119
120                 // Include the application selector
121                 require(PATH . "inc/selector.php");
122
123         } // END - main()
124
125 } // END - class
126
127 // Do not remove the following line:
128 ApplicationEntryPoint::main();
129
130 // [EOF]
131 ?>