Changed application initialization
authorAlexander Ebert <ebert@woltlab.com>
Tue, 6 Nov 2012 01:14:06 +0000 (02:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 6 Nov 2012 01:14:06 +0000 (02:14 +0100)
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/application/AbstractApplication.class.php
wcfsetup/install/files/lib/system/application/IApplication.class.php

index f13fca5f1fdc7a6cea31a0bd603bb009de3a59e0..14dd4f24241efd682c8739c7901d190de155b070 100644 (file)
@@ -407,9 +407,12 @@ class WCF {
                // do not init applications if within wcf
                if (PACKAGE_ID == 1) return;
                
+               // step 1) load all applications
+               $loadedApplications = array();
+               
                // start main application
                $application = ApplicationHandler::getInstance()->getActiveApplication();
-               $this->loadApplication($application);
+               $loadedApplications[] = $this->loadApplication($application);
                
                // register primary application
                $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
@@ -418,7 +421,12 @@ class WCF {
                // start dependent applications
                $applications = ApplicationHandler::getInstance()->getDependentApplications();
                foreach ($applications as $application) {
-                       $this->loadApplication($application, true);
+                       $loadedApplications[] = $this->loadApplication($application, true);
+               }
+               
+               // step 2) run each application
+               foreach ($loadedApplications as $application) {
+                       $application->__run();
                }
        }
        
@@ -427,8 +435,10 @@ class WCF {
         * 
         * @param       wcf\data\application\Application                $application
         * @param       boolean                                         $isDependentApplication
+        * @return      wcf\system\application\IApplication
         */
        protected function loadApplication(Application $application, $isDependentApplication = false) {
+               $applicationObject = null;
                $package = PackageCache::getInstance()->getPackage($application->packageID);
                
                $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
@@ -455,7 +465,8 @@ class WCF {
                                $this->getTPL()->addApplication($abbreviation, $application->packageID, $packageDir . 'templates/');
                                
                                // init application and assign it as template variable
-                               $this->getTPL()->assign('__'.$abbreviation, call_user_func(array($className, 'getInstance')));
+                               $applicationObject = call_user_func(array($className, 'getInstance'));
+                               $this->getTPL()->assign('__'.$abbreviation, $applicationObject);
                        }
                }
                else {
@@ -474,6 +485,8 @@ class WCF {
                
                // register application
                self::$applications[$abbreviation] = $application;
+               
+               return $applicationObject;
        }
        
        /**
index 645d5c35ff7926d34fe52eda1453d1a08d99080d..f0d411daa302a699ff6b18b296464a30c9e27554 100644 (file)
@@ -13,6 +13,16 @@ use wcf\system\SingletonFactory;
  * @category   Community Framework
  */
 abstract class AbstractApplication extends SingletonFactory implements IApplication {
+       /**
+        * @see wcf\system\SingletonFactory::init()
+        */
+       protected final function init() { }
+       
+       /**
+        * @see wcf\system\application\IApplication::__run()
+        */
+       abstract public function __run();
+       
        /**
         * @see wcf\system\application\IApplication::__callStatic()
         */
index bdb45c2e3204195b39707c1a3e47da0db1eb2abd..ed34e33475537f0d1d80ce4ce86d75a504d09f46 100644 (file)
@@ -12,6 +12,11 @@ namespace wcf\system\application;
  * @category   Community Framework
  */
 interface IApplication {
+       /**
+        * Initializes this application, called after all applications have been loaded.
+        */
+       public function __run();
+       
        /**
         * Forwards unknown method calls to WCF.
         *