index.php

Go to the documentation of this file.
00001 <?php
00002 // Developer mode active? Comment out if no dev!
00003 define('DEVELOPER', true);
00004 //xdebug_start_trace();
00032 class ApplicationEntryPoint {
00038         private static $instances = array (
00039                 'cfg',    // The configuration system
00040                 'loader', // The class loader system
00041                 'debug',  // Debug output
00042                 'db',     // Database layer
00043                 'io',     // Base I/O system (local file [or network])
00044                 'engine', // Template engine ( for ApplicationEntryPoint::app_die() )
00045                 'lang',   // Language sub-system
00046                 'app',    // The ApplicationHelper instance
00047         );
00048 
00058         public static function app_die ($message = "", $code = false, $extraData = "", $silentMode = false) {
00059                 // Is this method already called?
00060                 if (defined('EMERGENCY_EXIT_CALLED')) {
00061                         // Then output the text directly
00062                         die($message);
00063                 } // END - if
00064 
00065                 // This method shall not be called twice
00066                 define('EMERGENCY_EXIT_CALLED', true);
00067 
00068                 // Is a message set?
00069                 if (empty($message)) {
00070                         // No message provided
00071                         $message = "No message provided!";
00072                 } // END - if
00073 
00074                 // Get config instance
00075                 $configInstance = FrameworkConfiguration::getInstance();
00076 
00077                 // Do we have debug installation?
00078                 if (($configInstance->readConfig('product_install_mode') == "productive") || ($silentMode === true)) {
00079                         // Abort here
00080                         die();
00081                 } // END - if
00082 
00083                 // Get some instances
00084                 $tpl = FrameworkConfiguration::getInstance()->readConfig('template_class');
00085                 $lang = LanguageSystem::getInstance();
00086                 $io = FileIoHandler::getInstance();
00087 
00088                 // Get response instance
00089                 $responseInstance = ApplicationHelper::getInstance()->getResponseInstance();
00090 
00091                 // Is the template engine loaded?
00092                 if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
00093                         // Use the template engine for putting out (nicer look) the message
00094                         try {
00095                                 // Get the template instance from our object factory
00096                                 $templateInstance = ObjectFactory::createObjectByName($tpl, array(FrameworkConfiguration::getInstance()->readConfig('tpl_base_path'), $lang, $io));
00097                         } catch (FrameworkException $e) {
00098                                 die(sprintf("[Main:] Could not initialize template engine for reason: <span class=\"exception_reason\">%s</span>",
00099                                         $e->getMessage()
00100                                 ));
00101                         }
00102 
00103                         // Get and prepare backtrace for output
00104                         $backtraceArray = debug_backtrace();
00105                         $backtrace = "";
00106                         foreach ($backtraceArray as $key => $trace) {
00107                                 if (!isset($trace['file'])) $trace['file'] = __FILE__;
00108                                 if (!isset($trace['line'])) $trace['line'] = __LINE__;
00109                                 if (!isset($trace['args'])) $trace['args'] = array();
00110                                 $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
00111                         } // END - foreach
00112 
00113                         // Init application instance
00114                         $appInstance = null;
00115 
00116                         // Is the class there?
00117                         if (class_exists('ApplicationHelper')) {
00118                                 // Get application instance
00119                                 $appInstance = ApplicationHelper::getInstance();
00120 
00121                                 // Assign application data
00122                                 $templateInstance->assignApplicationData($appInstance);
00123                         } // END - if
00124 
00125                         // Assign variables
00126                         $templateInstance->assignVariable('message', $message);
00127                         $templateInstance->assignVariable('code', $code);
00128                         $templateInstance->assignVariable('extra', $extraData);
00129                         $templateInstance->assignVariable('backtrace', $backtrace);
00130                         $templateInstance->assignVariable('total_includes', ClassLoader::getInstance()->getTotal());
00131                         $templateInstance->assignVariable('total_objects', ObjectFactory::getTotal());
00132                         $templateInstance->assignVariable('title', $lang->getMessage('emergency_exit_title'));
00133 
00134                         // Load the template
00135                         $templateInstance->loadCodeTemplate('emergency_exit');
00136 
00137                         // Compile the template
00138                         $templateInstance->compileTemplate();
00139 
00140                         // Compile all variables
00141                         $templateInstance->compileVariables();
00142 
00143                         // Transfer data to response
00144                         $templateInstance->transferToResponse($responseInstance);
00145 
00146                         // Flush the response
00147                         $responseInstance->flushBuffer();
00148 
00149                         // Good bye...
00150                         exit();
00151                 } else {
00152                         // Output message and die
00153                         die(sprintf("[Main:] Emergency exit reached: <span class=\"emergency_span\">%s</span>",
00154                                 $message
00155                         ));
00156                 }
00157         }
00158 
00167         public static function main () {
00168                 // Some non-global common arrays we need...
00169                 global $_SERVER;
00170 
00171                 // Load config file
00172                 require(dirname(__FILE__) . '/inc/config.php');
00173 
00174                 // Load all include files
00175                 require($cfg->readConfig('base_path') . 'inc/includes.php');
00176 
00177                 // Load all framework classes
00178                 require($cfg->readConfig('base_path') . 'inc/classes.php');
00179 
00180                 // Include the application selector
00181                 require($cfg->readConfig('base_path') . 'inc/selector.php');
00182         } // END - main()
00183 
00184 } // END - class
00185 
00186 // Do not remove the following line:
00187 ApplicationEntryPoint::main();
00188 
00189 // [EOF]
00190 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6