--- /dev/null
+<?php
+namespace wcf\data\package;
+use wcf\system\cache\CacheHandler;
+use wcf\system\SingletonFactory;
+
+/**
+ * Manages the package cache.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage data.package
+ * @category Community Framework
+ */
+class PackageCache extends SingletonFactory {
+ /**
+ * list of cached packages
+ * @var array<wcf\data\package\Package>
+ */
+ protected $packages = array();
+
+ /**
+ * @see wcf\system\SingletonFactory::init()
+ */
+ protected function init() {
+ CacheHandler::getInstance()->addResource('package', WCF_DIR.'cache/cache.package.php', 'wcf\system\cache\builder\PackageCacheBuilder');
+ $this->packages = CacheHandler::getInstance()->get('package');
+ }
+
+ /**
+ * Returns a specific package.
+ *
+ * @param integer $packageID
+ * @return wcf\data\package\Package
+ */
+ public function getPackage($packageID) {
+ if (isset($this->packages[$packageID])) return $this->packages[$packageID];
+
+ return null;
+ }
+}
namespace wcf\system;
use wcf\data\application\Application;
use wcf\data\package\Package;
+use wcf\data\package\PackageCache;
use wcf\system\application\ApplicationHandler;
use wcf\system\cache\CacheHandler;
use wcf\system\database\statement\PreparedStatement;
protected function initApplications() {
if (PACKAGE_ID == 1) return;
- // prepare statement
- $sql = "SELECT package, packageDir
- FROM wcf".WCF_N."_package
- WHERE packageID = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
-
// start main application
$application = ApplicationHandler::getInstance()->getActiveApplication();
- $this->loadApplication($statement, $application);
+ $this->loadApplication($application);
// start dependent applications
$applications = ApplicationHandler::getInstance()->getDependentApplications();
foreach ($applications as $application) {
- $this->loadApplication($statement, $application, true);
+ $this->loadApplication($application, true);
}
}
/**
* Loads an application.
*
- * @param wcf\system\database\statement\PreparedStatement $statement
* @param wcf\data\application\Application $application
* @param boolean $isDependentApplication
*/
- protected function loadApplication(PreparedStatement $statement, Application $application, $isDepedentApplication = false) {
- $statement->execute(array($application->packageID));
- $row = $statement->fetchArray();
+ protected function loadApplication(Application $application, $isDepedentApplication = false) {
+ $package = PackageCache::getInstance()->getPackage($application->packageID);
$abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
- $packageDir = util\FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
+ $packageDir = util\FileUtil::getRealPath(WCF_DIR.$package->packageDir);
self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
$className = $abbreviation.'\system\\'.strtoupper($abbreviation).'Core';
require_once($configPath);
}
else {
- throw new exception\SystemException('Unable to load configuration for '.$row['package']);
+ throw new exception\SystemException('Unable to load configuration for '.$package->package);
}
// start application if not within ACP
}
else {
unset(self::$autoloadDirectories[$abbreviation]);
- throw new exception\SystemException('Unable to run '.$row['package'].', '.$className.' missing.');
+ throw new exception\SystemException('Unable to run '.$row->package.', '.$className.' missing.');
}
// load application settings if not within ACP