class WCF {
/**
* list of currently loaded applications
- * @var array<\wcf\system\application\IApplication>
+ * @var array<\wcf\data\application\Application>
*/
protected static $applications = array();
+ /**
+ * list of currently loaded application objects
+ * @var array<\wcf\system\application\IApplication>
+ */
+ protected static $applicationObjects = array();
+
/**
* list of autoload directories
* @var array
}
// init application and assign it as template variable
- $applicationObject = call_user_func(array($className, 'getInstance'));
- $this->getTPL()->assign('__'.$abbreviation, $applicationObject);
+ self::$applicationObjects[$application->packageID] = call_user_func(array($className, 'getInstance'));
+ $this->getTPL()->assign('__'.$abbreviation, self::$applicationObjects[$application->packageID]);
}
else {
unset(self::$autoloadDirectories[$abbreviation]);
// register application
self::$applications[$abbreviation] = $application;
- return $applicationObject;
+ return self::$applicationObjects[$application->packageID];
+ }
+
+ /**
+ * Returns the corresponding application object. Does not support the 'wcf' pseudo application.
+ *
+ * @param wcf\data\application\Application $application
+ * @return \wcf\system\application\IApplication
+ */
+ public static function getApplicationObject(Application $application) {
+ if (isset(self::$applicationObjects[$application->packageID])) {
+ return self::$applicationObjects[$application->packageID];
+ }
+
+ return null;
}
/**
*/
protected $packageID = 0;
+ /**
+ * qualified name of application's primary controller
+ * @var string
+ */
+ protected $primaryController = '';
+
/**
* @see \wcf\system\SingletonFactory::init()
*/
return PackageCache::getInstance()->getPackage($this->packageID);
}
+ /**
+ * @see \wcf\system\application\IApplication::getPrimaryController()
+ */
+ public function getPrimaryController() {
+ return $this->primaryController;
+ }
+
/**
* @see \wcf\system\application\IApplication::__callStatic()
*/
<?php
namespace wcf\system\request;
+use wcf\system\application\AbstractApplication;
use wcf\system\application\ApplicationHandler;
use wcf\system\exception\AJAXException;
use wcf\system\exception\IllegalLinkException;
$routeData['controller'] = $landingPage->getController();
}
else {
+ // check if current URL matches an application but controller was omitted
+ $currentRequestURI = RouteHandler::getHost() . $requestUri;
+ foreach (ApplicationHandler::getInstance()->getApplications() as $application) {
+ if ($currentRequestURI == $application->getPageURL()) {
+ if ($controller = WCF::getApplicationObject($application)->getPrimaryController()) {
+ $controller = explode('\\', $controller);
+ HeaderUtil::redirect(LinkHandler::getInstance()->getLink(array_pop($controller), array('application' => $controller[0])));
+ exit;
+ }
+ }
+
+ }
+
// redirect to landing page
HeaderUtil::redirect($landingPage->getLink(), true);
exit;