New starter/init style applied
authorRoland Häder <roland@mxchange.org>
Wed, 11 Jun 2008 23:11:39 +0000 (23:11 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 11 Jun 2008 23:11:39 +0000 (23:11 +0000)
application/hub/init.php
application/hub/loader.php
index.php

index 4ac89d3319663640fea2aa0567f48b3cbd5fe387..67d489cbc2f4666f41ee32d6366494495f27cc75 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// Get an instance of the helper
-$eval = sprintf("\$app = %s::getInstance();",
-       FrameworkConfiguration::getInstance()->readConfig("app_helper_class")
-);
-eval($eval);
-
-// Set application name and version
-$app->setAppName("MXChange Hub");
-$app->setAppVersion("0.0.0");
-$app->setAppShortName("mxhub");
-
-// Get's our IP address
-$_SERVER['SERVER_ADDR'] = ConsoleTools::aquireSelfIPAddress();
-
 // Initialize output system
 require(PATH . "inc/output.php");
 
@@ -57,10 +43,28 @@ require(PATH . "inc/language.php");
 
 // This application needs a database connection then we have to simply include
 // the inc/database.php script
-require(sprintf("%sinc/database%s",
-       PATH,
-       FrameworkConfiguration::getInstance()->readConfig("php_extension")
-));
+require(PATH . "inc/database.php");
+
+// Generate call-back function
+$callback = sprintf("%s::getInstance",
+       FrameworkConfiguration::getInstance()->readConfig('app_helper_class')
+);
+
+// Get an instance of the helper
+$app = call_user_func_array($callback, array());
+
+// Set application name and version
+$app->setAppName("MXChange Hub");
+$app->setAppVersion("0.0.0");
+$app->setAppShortName("mxhub");
+
+// Get's our IP address
+$_SERVER['SERVER_ADDR'] = ConsoleTools::aquireSelfIPAddress();
+
+// Set instances
+$app->setFileIoInstance($io);
+$app->setLanguageInstance($lang);
+$app->setDatabaseInstance($db);
 
 // [EOF]
-?>
+?>
\ No newline at end of file
index 08c2de0143423803eaa58971eaea69eb6a6fd497..1c153b69ce85530cd744d907a3b8d3c150f7d3bf 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// Is the instance variable set?
-if (!isset($application)) {
-       // We need this!
-       ApplicationEntryPoint::app_die("[Main:] Interne Variable <strong>application</strong> nicht gefunden!");
-}
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
 
 // Load all classes for the application
 foreach ($lowerClasses as $class) {
        // Try to load the application classes
        try {
-               ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", FrameworkConfiguration::getInstance()->readConfig("application_path"), $application, $class));
+               ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", $cfg->readConfig("application_path"), $cfg->readConfig("app_name"), $class));
        } catch (PathIsNoDirectoryException $e) {
                ApplicationEntryPoint::app_die(sprintf("[Main:] Kann Applikationsklassen im Pfad <strong>%s</strong> nicht laden. Reason: <strong>%s</strong>",
                        $class,
index 9cabcb0a844cabeadea6e465976870f6ee4bf10d..947baf3c9a43fc3436c1a88d8b78c3b994f3b9a9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,4 +1,8 @@
 <?php
+// Developer mode active? Comment out if no dev!
+define('DEVELOPER', true);
+
+//xdebug_start_trace();
 /**
  * The main class with the entry point to the whole application. This class
  * "emulates" Java(tm)'s entry point call. Additionally it covers local
@@ -33,8 +37,8 @@ class ApplicationEntryPoint {
         * @return      void
         */
        private static $instances = array (
-               'cfg',  // The configuration system
-               'loader',       // The class loader system
+               'cfg',    // The configuration system
+               'loader', // The class loader system
                'debug',  // Debug output
                'db',     // Database layer
                'io',     // Base I/O system (local file [or network])
@@ -66,35 +70,30 @@ class ApplicationEntryPoint {
                }
 
                // Get some instances
-               $tpl = FrameworkConfiguration::getInstance()->readConfig("tpl_engine");
+               $tpl = FrameworkConfiguration::getInstance()->readConfig('tpl_engine');
                $lang = LanguageSystem::getInstance();
-               $io = FileIOHandler::getInstance();
+               $io = FileIoHandler::getInstance();
 
                // Is the template engine loaded?
                if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
                        // Use the template engine for putting out (nicer look) the message
                        try {
-                               $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", \$lang, \$io);",
-                                       FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
-                                       FrameworkConfiguration::getInstance()->readConfig("tpl_engine"),
-                                       PATH,
-                                       FrameworkConfiguration::getInstance()->readConfig("tpl_base_path")
-                               );
-                               eval($eval);
+                               // Get the template instance from our object factory
+                               $tplEngine = ObjectFactory::createObjectByConfiguredName('tpl_engine', array(FrameworkConfiguration::getInstance()->readConfig('tpl_base_path'), $lang, $io));
                        } catch (BasePathIsEmptyException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        } catch (InvalidBasePathStringException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        } catch (BasePathIsNoDirectoryException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        } catch (BasePathReadProtectedException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        }
@@ -110,11 +109,12 @@ class ApplicationEntryPoint {
                        }
 
                        // Assign variables
-                       $tplEngine->assignVariable("message", $message);
-                       $tplEngine->assignVariable("backtrace", $backtrace);
+                       $tplEngine->assignVariable('message', $message);
+                       $tplEngine->assignVariable('backtrace', $backtrace);
+                       $tplEngine->assignVariable('total_objects', ObjectFactory::getTotal());
 
                        // Load the template
-                       $tplEngine->loadCodeTemplate("emergency_exit");
+                       $tplEngine->loadCodeTemplate('emergency_exit');
 
                        // Compile the template
                        $tplEngine->compileTemplate();
@@ -148,16 +148,16 @@ class ApplicationEntryPoint {
                global $_SERVER;
 
                // Load config file
-               require(dirname(__FILE__) . "/inc/config.php");
+               require(dirname(__FILE__) . '/inc/config.php');
 
                // Load all include files
-               require(PATH . "inc/includes.php");
+               require(PATH . 'inc/includes.php');
 
                // Load all framework classes
-               require(PATH . "inc/classes.php");
+               require(PATH . 'inc/classes.php');
 
                // Include the application selector
-               require(PATH . "inc/selector.php");
+               require(PATH . 'inc/selector.php');
 
        } // END - main()