Application init phase rewritten, data.php now sets app data
authorRoland Häder <roland@mxchange.org>
Fri, 3 Oct 2008 01:00:31 +0000 (01:00 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 3 Oct 2008 01:00:31 +0000 (01:00 +0000)
18 files changed:
.gitattributes
application/blog/data.php [new file with mode: 0644]
application/blog/init.php
application/selector/class_ApplicationSelector.php
application/selector/data.php [new file with mode: 0644]
application/selector/init.php
application/ship-simu/data.php [new file with mode: 0644]
application/ship-simu/init.php
application/shoutbox/data.php [new file with mode: 0644]
application/shoutbox/init.php
application/todo/data.php [new file with mode: 0644]
application/todo/init.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/factories/objects/class_ObjectFactory.php
inc/database.php
inc/file_io.php
inc/language.php
inc/selector.php

index 616fec2..e57ab49 100644 (file)
@@ -4,6 +4,7 @@ application/.htaccess -text
 application/blog/.htaccess -text
 application/blog/class_ApplicationHelper.php -text
 application/blog/config.php -text
+application/blog/data.php -text
 application/blog/debug.php -text
 application/blog/exceptions.php -text
 application/blog/exceptions/.htaccess -text
@@ -47,6 +48,7 @@ application/selector/.htaccess -text
 application/selector/class_ApplicationHelper.php -text
 application/selector/class_ApplicationSelector.php -text
 application/selector/config.php -text
+application/selector/data.php -text
 application/selector/debug.php -text
 application/selector/exceptions.php -text
 application/selector/init.php -text
@@ -60,6 +62,7 @@ application/selector/templates/de/code/selector_main.ctp -text
 application/ship-simu/.htaccess -text
 application/ship-simu/class_ApplicationHelper.php -text
 application/ship-simu/config.php -text
+application/ship-simu/data.php -text
 application/ship-simu/debug.php -text
 application/ship-simu/exceptions.php -text
 application/ship-simu/exceptions/.htaccess -text
@@ -236,6 +239,7 @@ application/ship-simu/templates/images/de/image/code_captcha.itp -text
 application/shoutbox/.htaccess -text
 application/shoutbox/class_ApplicationHelper.php -text
 application/shoutbox/config.php -text
+application/shoutbox/data.php -text
 application/shoutbox/debug.php -text
 application/shoutbox/exceptions.php -text
 application/shoutbox/exceptions/.htaccess -text
@@ -278,6 +282,7 @@ application/shoutbox/templates/images/de/image/code_captcha.itp -text
 application/todo/.htaccess -text
 application/todo/class_ApplicationHelper.php -text
 application/todo/config.php -text
+application/todo/data.php -text
 application/todo/debug.php -text
 application/todo/exceptions.php -text
 application/todo/exceptions/.htaccess -text
diff --git a/application/blog/data.php b/application/blog/data.php
new file mode 100644 (file)
index 0000000..e89cd58
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Application data
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * You can prevent adding this application to the selector by uncommenting the
+ * following line:
+ *
+ * if ((isset($this)) && (is_object($this)) && ($this->isClass("ApplicationSelector"))) { return; }
+ *
+ * isset() is required to prevent a warning and is_object() is highly required
+ * when the application itself is requested in URL (hint: index.php?app=your_app)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
+
+// Get an instance of the helper
+$app = call_user_func_array(
+       array($cfg->readConfig('app_helper_class'), "getInstance"),
+       array()
+);
+
+// Set application name and version
+$app->setAppName("Nameless Blogging Software");
+$app->setAppVersion("0.0.0");
+$app->setAppShortName("blog");
+
+// [EOF]
+?>
index fa7aee2..39c5bed 100644 (file)
@@ -49,23 +49,5 @@ require($cfg->readConfig('base_path') . 'inc/language.php');
 // the inc/database.php script
 require($cfg->readConfig('base_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("Nameless Blogging Software");
-$app->setAppVersion("0.0.0");
-$app->setAppShortName("blog");
-
-// Set instances
-$app->setFileIoInstance($io);
-$app->setLanguageInstance($lang);
-$app->setDatabaseInstance($db);
-
 // [EOF]
 ?>
index 0d366b7..f52b50a 100644 (file)
@@ -109,18 +109,18 @@ class ApplicationSelector extends BaseFrameworkSystem {
        }
 
        /**
-        * Load the init.php script of an application and append the application
+        * Load the data.php script of an application and append the application
         * instance to $foundApps
         *
-        * @param       $initScript     The FQFN of init.php
+        * @param       $appData                The FQFN of data.php
         * @param       $appName                The application's Uni* name
         * @return      void
         */
-       private function loadInitScript ($initScript, $appName) {
+       private function loadApplicationData ($appData, $appName) {
                // Is it a file and readable?
-               if ((is_file($initScript)) && (is_readable($initScript))) {
+               if ((is_file($appData)) && (is_readable($appData))) {
                        // Then include it
-                       include ($initScript);
+                       include ($appData);
 
                        // Add the current instance to the list
                        $this->foundApps->append($app);
@@ -206,15 +206,13 @@ class ApplicationSelector extends BaseFrameworkSystem {
 
                        // Is this a readable directory? (files will be ignored silently)
                        if ((is_dir($fqfn)) && (is_readable($fqfn))) {
-                               // Then get the init.php script for analyzing
-                               $initScript = sprintf("%s/init.php", $fqfn);
+                               // Then get the data.php script for analyzing
+                               $appData = sprintf("%s/data.php", $fqfn);
 
-                               // Load the application's init.php script and append the
+                               // Load the application's data.php script and append the
                                // application to the ArrayObject
-                               $this->loadInitScript($initScript, $appName);
-
-                       } // END - if ((is_dir(...
-
+                               $this->loadApplicationData($appData, $appName);
+                       } // END - if
                } // END - while
 
                // Close directory pointer
diff --git a/application/selector/data.php b/application/selector/data.php
new file mode 100644 (file)
index 0000000..29d47ef
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Application data
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
+
+// Get an instance of the helper
+$app = call_user_func_array(
+       array($cfg->readConfig('app_helper_class'), "getInstance"),
+       array()
+);
+
+// Set application name and version
+$app->setAppName("Applikationsausw&auml;hler");
+$app->setAppVersion("0.1a");
+$app->setAppShortName($cfg->readConfig('selector_name'));
+
+// [EOF]
+?>
index 71893f0..3b9e2db 100644 (file)
@@ -37,22 +37,5 @@ require($cfg->readConfig('base_path') . 'inc/file_io.php');
 // Include the language sub-system
 require($cfg->readConfig('base_path') . 'inc/language.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("Applikationsausw&auml;hler");
-$app->setAppVersion("0.1a");
-$app->setAppShortName(FrameworkConfiguration::getInstance()->readConfig('selector_name'));
-
-// Set instances
-$app->setFileIoInstance($io);
-$app->setLanguageInstance($lang);
-
 // [EOF]
 ?>
diff --git a/application/ship-simu/data.php b/application/ship-simu/data.php
new file mode 100644 (file)
index 0000000..0ec07a0
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Application data
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * You can prevent adding this application to the selector by uncommenting the
+ * following line:
+ *
+ * if ((isset($this)) && (is_object($this)) && ($this->isClass("ApplicationSelector"))) { return; }
+ *
+ * isset() is required to prevent a warning and is_object() is highly required
+ * when the application itself is requested in URL (hint: index.php?app=your_app)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
+
+// Get an instance of the helper
+$app = call_user_func_array(
+       array($cfg->readConfig('app_helper_class'), "getInstance"),
+       array()
+);
+
+// Set application name and version
+$app->setAppName("Ship-Simu Schiffsimulator");
+$app->setAppVersion("0.0.0");
+$app->setAppShortName("ship-simu");
+
+// [EOF]
+?>
index 7b65cae..39c5bed 100644 (file)
@@ -49,23 +49,5 @@ require($cfg->readConfig('base_path') . 'inc/language.php');
 // the inc/database.php script
 require($cfg->readConfig('base_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("Ship-Simu Schiffsimulator");
-$app->setAppVersion("0.0.0");
-$app->setAppShortName("ship-simu");
-
-// Set instances
-$app->setFileIoInstance($io);
-$app->setLanguageInstance($lang);
-$app->setDatabaseInstance($db);
-
 // [EOF]
 ?>
diff --git a/application/shoutbox/data.php b/application/shoutbox/data.php
new file mode 100644 (file)
index 0000000..d97c702
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Application data
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * You can prevent adding this application to the selector by uncommenting the
+ * following line:
+ *
+ * if ((isset($this)) && (is_object($this)) && ($this->isClass("ApplicationSelector"))) { return; }
+ *
+ * isset() is required to prevent a warning and is_object() is highly required
+ * when the application itself is requested in URL (hint: index.php?app=your_app)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
+
+// Get an instance of the helper
+$app = call_user_func_array(
+       array($cfg->readConfig('app_helper_class'), "getInstance"),
+       array()
+);
+
+// Set application name and version
+$app->setAppName("Nameless Blogging Software");
+$app->setAppVersion("0.0.0");
+$app->setAppShortName("shoutbox");
+
+// [EOF]
+?>
index 117b295..39c5bed 100644 (file)
@@ -49,23 +49,5 @@ require($cfg->readConfig('base_path') . 'inc/language.php');
 // the inc/database.php script
 require($cfg->readConfig('base_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("Nameless Blogging Software");
-$app->setAppVersion("0.0.0");
-$app->setAppShortName("shoutbox");
-
-// Set instances
-$app->setFileIoInstance($io);
-$app->setLanguageInstance($lang);
-$app->setDatabaseInstance($db);
-
 // [EOF]
 ?>
diff --git a/application/todo/data.php b/application/todo/data.php
new file mode 100644 (file)
index 0000000..df4b3bf
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Application data
+ *
+ * Please remember that this include file is being loaded *before* the class
+ * loader is loading classes from "exceptions", "interfaces" and "main"!
+ *
+ * You can prevent adding this application to the selector by uncommenting the
+ * following line:
+ *
+ * if ((isset($this)) && (is_object($this)) && ($this->isClass("ApplicationSelector"))) { return; }
+ *
+ * isset() is required to prevent a warning and is_object() is highly required
+ * when the application itself is requested in URL (hint: index.php?app=your_app)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
+
+// Get an instance of the helper
+$app = call_user_func_array(
+       array($cfg->readConfig('app_helper_class'), "getInstance"),
+       array()
+);
+
+// Set application name and version
+$app->setAppName("OpenToDo");
+$app->setAppVersion("0.0.0");
+$app->setAppShortName("todo");
+
+// [EOF]
+?>
index c8d19e3..39c5bed 100644 (file)
@@ -49,23 +49,5 @@ require($cfg->readConfig('base_path') . 'inc/language.php');
 // the inc/database.php script
 require($cfg->readConfig('base_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("OpenToDo");
-$app->setAppVersion("0.0.0");
-$app->setAppShortName("todo");
-
-// Set instances
-$app->setFileIoInstance($io);
-$app->setLanguageInstance($lang);
-$app->setDatabaseInstance($db);
-
 // [EOF]
 ?>
index 38e689b..006a6b4 100644 (file)
@@ -269,6 +269,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        private final function initInstance () {
                // Is this a system class?
                if (!in_array($this->__toString(), $this->systemClasses)) {
+                       // Set configuration instance
+                       $this->setConfigInstance(FrameworkConfiguration::getInstance());
+
                        // Add application helper to our class
                        $this->systemclasses[] = $this->getConfigInstance()->readConfig('app_helper_class');
 
index 06c73d8..0848e79 100644 (file)
@@ -64,14 +64,13 @@ class ObjectFactory extends BaseFactory {
                        throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
                }
 
-               // Then Prepare the call-back function
-               $callback = sprintf("%s::create%s",
-                       $className,
+               // Create method name
+               $methodName = sprintf("create%s",
                        $className
                );
 
                // Run the user function
-               $objectInstance = call_user_func_array($callback, $args);
+               $objectInstance = call_user_func_array(array($className, $methodName), $args);
 
                // Count generated objects up
                self::$total++;
index f274f6c..52d7506 100644 (file)
@@ -77,6 +77,9 @@ try {
        ));
 }
 
+// Is the app variable there and valid?
+if (is_object($app)) $app->setDatabaseInstance($db);
+
 // Datenbankobjekt debuggen
 if (defined('DEBUG_DATABASE_OBJ')) {
        DebugMiddleware::getInstance()->output(sprintf("The database sub-system does now look like this:<br />
index 0a5ec9b..c141fea 100644 (file)
@@ -27,5 +27,8 @@
 // Get the instance
 $io = ObjectFactory::createObjectByConfiguredName('file_io_class');
 
+// Is the app variable there and valid?
+if (is_object($app)) $app->setFileIoInstance($io);
+
 // [EOF]
 ?>
index 6db17c0..b9250e5 100644 (file)
@@ -43,5 +43,8 @@ try {
        ));
 }
 
+// Is the app variable there and valid?
+if (is_object($app)) $app->setLanguageInstance($lang);
+
 // [EOF]
 ?>
index 819485e..d20cbcb 100644 (file)
@@ -29,6 +29,7 @@ $cfg = FrameworkConfiguration::getInstance();
 $configAppIncludes = array(
        sprintf("class_%s", $cfg->readConfig('app_helper_class')), // The ApplicationHelper class
        "config",               // The application's own configuration
+       "data",                 // Application data
        "init",                 // The application initializer
        "loader",               // The application's class loader
        "debug",                // Some debugging stuff