Added AbstractApplication::isActiveApplication()
authorAlexander Ebert <ebert@woltlab.com>
Wed, 26 Dec 2012 03:28:16 +0000 (04:28 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 26 Dec 2012 03:28:16 +0000 (04:28 +0100)
If you're developing an own application, simply add a protected variable "$abbreviation" and assign the application's abbreviation (e.g. "wbb"). Furthermore the package id is automatically set and can be accessed through $this->packageID.

In case you're setting the active page menu item and adding a "top" breadcrumb for your application, please do so if $this->isActiveApplication() returns true. If you fail to check this, multiple applications will stack their breadcrumbs and the active page menu item would no longer be deterministic.

wcfsetup/install/files/lib/system/application/AbstractApplication.class.php
wcfsetup/install/files/lib/system/application/IApplication.class.php

index b6fd0acf079e1ca7428807484a409bc824c2952c..da3865b50fbc7bb76e04815a311f1a9e9615cc47 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\application;
+use wcf\system\exception\SystemException;
 use wcf\system\SingletonFactory;
 
 /**
@@ -13,10 +14,51 @@ use wcf\system\SingletonFactory;
  * @category   Community Framework
  */
 abstract class AbstractApplication extends SingletonFactory implements IApplication {
+       /**
+        * application's abbreviation
+        * @var string
+        */
+       protected $abbreviation = '';
+       
+       /**
+        * true, if current application is active (directly invoked, not dependent)
+        * @var boolean
+        */
+       protected $isActiveApplication = false;
+       
+       /**
+        * application's package id
+        * @var integer
+        */
+       protected $packageID = 0;
+       
        /**
         * @see wcf\system\SingletonFactory::init()
         */
-       protected final function init() { }
+       protected final function init() {
+               if (empty($this->abbreviation) || $this->abbreviation == 'wcf') {
+                       throw new SystemException("Unable to determine application, abbreviation is missing");
+               }
+               
+               $application = ApplicationHandler::getInstance()->getApplication($this->abbreviation);
+               if ($application === null) {
+                       throw new SystemException("Unable to determine application, abbreviation is unknown");
+               }
+               
+               $this->packageID = $application->packageID;
+               
+               // check if current application is active (directly invoked, not dependent)
+               if ($application->packageID == ApplicationHandler::getInstance()->getActiveApplication()->packageID) {
+                       $this->isActiveApplication = true;
+               }
+       }
+       
+       /**
+        * @see wcf\system\application\IApplication::isActiveApplication()
+        */
+       public function isActiveApplication() {
+               return $this->isActiveApplication;
+       }
        
        /**
         * @see wcf\system\application\IApplication::__callStatic()
index ed34e33475537f0d1d80ce4ce86d75a504d09f46..d6c88b052d4f5ac846086760e8b3a0b7f59eca3d 100644 (file)
@@ -17,6 +17,13 @@ interface IApplication {
         */
        public function __run();
        
+       /**
+        * Returns true, if current application is treated as active and was invoked directly.
+        *
+        * @return      boolean
+        */
+       public function isActiveApplication();
+       
        /**
         * Forwards unknown method calls to WCF.
         *