* Starts the session system.
*/
protected function initSession() {
- $factory = new SessionFactory();
+ $factory = self::$diContainer->get(SessionFactory::class);
$factory->load();
self::$sessionObj = self::$diContainer->get(SessionHandler::class);
mb_language('uni');
// get language
- self::$languageObj = LanguageFactory::getInstance()->getUserLanguage(self::getSession()->getLanguageID());
+ self::$languageObj = self::$diContainer->get(LanguageFactory::class)->getUserLanguage(self::getSession()->getLanguageID());
}
/**
self::getSession()->setStyleID(intval($_REQUEST['styleID']));
}
- /** @var $styleHandler \wcf\system\style\StyleHandler */
$styleHandler = self::$diContainer->get(StyleHandler::class);
$styleHandler->changeStyle(self::getSession()->getStyleID());
}
<?php
namespace wcf\system;
+use DI\ContainerBuilder;
use wcf\acp\form\MasterPasswordForm;
use wcf\acp\form\MasterPasswordInitForm;
use wcf\system\application\ApplicationHandler;
// define tmp directory
if (!defined('TMP_DIR')) define('TMP_DIR', FileUtil::getTempFolder());
+ $builder = new ContainerBuilder();
+ self::$diContainer = $builder->build();
+
// start initialization
$this->initDB();
$this->loadOptions();
* @see \wcf\system\WCF::initSession()
*/
protected function initSession() {
- $factory = new ACPSessionFactory();
+ $factory = self::$diContainer->get(ACPSessionFactory::class);
$factory->load();
- self::$sessionObj = SessionHandler::getInstance();
+ self::$sessionObj = self::$diContainer->get(SessionHandler::class);
}
/**
<?php
namespace wcf\system\language;
+use wcf\data\language\category\LanguageCategory;
use wcf\data\language\Language;
use wcf\data\language\LanguageEditor;
use wcf\system\cache\builder\LanguageCacheBuilder;
*/
protected $cache = null;
+ /**
+ * @var LanguageCacheBuilder
+ */
+ protected $languageCacheBuilder;
+
/**
* initialized languages
- * @var array<\wcf\data\language\Language>
+ * @var Language[]
*/
protected $languages = array();
/**
* active template scripting compiler
- * @var \wcf\system\template\TemplateScriptingCompiler
+ * @var TemplateScriptingCompiler
*/
protected $scriptingCompiler = null;
/**
- * @see \wcf\system\SingletonFactory::init()
+ * LanguageFactory constructor.
+ *
+ * @param LanguageCacheBuilder $languageCacheBuilder
+ */
+ public function __construct(LanguageCacheBuilder $languageCacheBuilder) {
+ $this->languageCacheBuilder = $languageCacheBuilder;
+
+ parent::__construct();
+ }
+
+ /**
+ * @see SingletonFactory::init()
*/
protected function init() {
$this->loadCache();
* Returns a Language object for the language with the given id.
*
* @param integer $languageID
- * @return \wcf\data\language\Language
+ * @return Language
*/
public function getLanguage($languageID) {
if (!isset($this->languages[$languageID])) {
* Gets the preferred language of the current user.
*
* @param integer $languageID
- * @return \wcf\data\language\Language
+ * @return Language
*/
public function getUserLanguage($languageID = 0) {
if ($languageID) {
* language exists.
*
* @param string $languageCode
- * @return \wcf\data\language\Language
+ * @return Language
*/
public function getLanguageByCode($languageCode) {
// called within WCFSetup
* Returns the language category with the given name.
*
* @param string $categoryName
- * @return \wcf\data\language\category\LanguageCategory
+ * @return LanguageCategory
*/
public function getCategory($categoryName) {
if (isset($this->cache['categories'][$categoryName])) {
* Returns language category by id.
*
* @param integer $languageCategoryID
- * @return \wcf\data\language\category\LanguageCategory
+ * @return LanguageCategory
*/
public function getCategoryByID($languageCategoryID) {
if (isset($this->cache['categoryIDs'][$languageCategoryID])) {
/**
* Returns a list of available language categories.
*
- * @return array<\wcf\data\language\category\LanguageCategory>
+ * @return LanguageCategory[]
*/
public function getCategories() {
return $this->cache['categories'];
/**
* Returns the active scripting compiler object.
*
- * @return \wcf\system\template\TemplateScriptingCompiler
+ * @return TemplateScriptingCompiler
*/
public function getScriptingCompiler() {
if ($this->scriptingCompiler === null) {
*/
protected function loadCache() {
if (defined('WCF_N')) {
- $this->cache = LanguageCacheBuilder::getInstance()->getData();
+ $this->cache = $this->languageCacheBuilder->getData();
}
}
* Clears languages cache.
*/
public function clearCache() {
- LanguageCacheBuilder::getInstance()->reset();
+ $this->languageCacheBuilder->reset();
}
/**
/**
* Returns all available languages.
*
- * @return array<\wcf\data\language\Language>
+ * @return Language[]
*/
public function getLanguages() {
return $this->cache['languages'];
/**
* Returns all available content languages for given package.
*
- * @return array<\wcf\data\language\Language>
+ * @return Language[]
*/
public function getContentLanguages() {
$availableLanguages = array();
*/
protected $applicationHandler;
+ /**
+ * @var PageMenu
+ */
+ protected $pageMenu;
+
/**
* @var RequestHandler
*/
* @param RequestHandler $requestHandler
* @param RouteHandler $routeHandler
*/
- public function __construct(ApplicationHandler $applicationHandler, RequestHandler $requestHandler, RouteHandler $routeHandler) {
+ public function __construct(ApplicationHandler $applicationHandler, PageMenu $pageMenu, RequestHandler $requestHandler, RouteHandler $routeHandler) {
$this->applicationHandler = $applicationHandler;
+ $this->pageMenu = $pageMenu;
$this->requestHandler = $requestHandler;
$this->routeHandler = $routeHandler;
$controller = 'Index';
}
else {
- return WCF::getDIContainer()->get(PageMenu::class)->getLandingPage()->getProcessor()->getLink();
+ return $this->pageMenu->getLandingPage()->getProcessor()->getLink();
}
}
*/
protected $isACPRequest = false;
+ /**
+ * @var PageMenu
+ */
+ protected $pageMenu;
+
/**
* @var RouteHandler
*/
* @param ControllerMap $controllerMap
* @param RouteHandler $routeHandler
*/
- public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, RouteHandler $routeHandler) {
+ public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, PageMenu $pageMenu, RouteHandler $routeHandler) {
$this->applicationHandler = $applicationHandler;
$this->controllerMap = $controllerMap;
+ $this->pageMenu = $pageMenu;
$this->routeHandler = $routeHandler;
parent::__construct();
return;
}
- $landingPage = WCF::getDIContainer()->get(PageMenu::class)->getLandingPage();
+ $landingPage = $this->pageMenu->getLandingPage();
if ($landingPage === null) {
return;
}
* @category Community Framework
*/
class ACPSessionFactory {
+ /**
+ * @var EventHandler
+ */
+ protected $eventHandler;
+
/**
* session editor class name
* @var string
*/
protected $sessionEditor = 'wcf\data\acp\session\ACPSessionEditor';
+ /**
+ * @var SessionHandler
+ */
+ protected $sessionHandler;
+
+ /**
+ * ACPSessionFactory constructor.
+ *
+ * @param EventHandler $eventHandler
+ * @param SessionHandler $sessionHandler
+ */
+ public function __construct(EventHandler $eventHandler, SessionHandler $sessionHandler) {
+ $this->eventHandler = $eventHandler;
+ $this->sessionHandler = $sessionHandler;
+ }
+
/**
* Loads the object of the active session.
*/
public function load() {
// get session
$sessionID = $this->readSessionID();
- SessionHandler::getInstance()->load($this->sessionEditor, $sessionID);
+ $this->sessionHandler->load($this->sessionEditor, $sessionID);
// call beforeInit event
if (!defined('NO_IMPORTS')) {
- EventHandler::getInstance()->fireAction($this, 'beforeInit');
+ $this->eventHandler->fireAction($this, 'beforeInit');
}
$this->init();
// call afterInit event
if (!defined('NO_IMPORTS')) {
- EventHandler::getInstance()->fireAction($this, 'afterInit');
+ $this->eventHandler->fireAction($this, 'afterInit');
}
}
* Initializes the session system.
*/
protected function init() {
- SessionHandler::getInstance()->initSession();
+ $this->sessionHandler->initSession();
}
/**
*/
public function hasValidCookie() {
if (isset($_COOKIE[COOKIE_PREFIX.'cookieHash'])) {
- if ($_COOKIE[COOKIE_PREFIX.'cookieHash'] == SessionHandler::getInstance()->sessionID) {
+ if ($_COOKIE[COOKIE_PREFIX.'cookieHash'] == $this->sessionHandler->sessionID) {
return true;
}
}
protected function init() {
if (!$this->hasValidCookie()) {
// cookie support will be enabled upon next request
- HeaderUtil::setCookie('cookieHash', SessionHandler::getInstance()->sessionID);
+ HeaderUtil::setCookie('cookieHash', $this->sessionHandler->sessionID);
}
// enable cookie support
- SessionHandler::getInstance()->enableCookies();
+ $this->sessionHandler->enableCookies();
parent::init();
}
$oldSessionID = $this->session->sessionID;
$newSessionID = StringUtil::getRandomID();
+ /** @var \wcf\data\DatabaseObjectEditor $sessionEditor */
$sessionEditor = new $this->sessionEditorClassName($this->session);
$sessionEditor->update(array(
'sessionID' => $newSessionID
* Returns the value of a session variable.
*
* @param string $key
+ * @return mixed
*/
public function getVar($key) {
if (isset($this->variables[$key])) {
/**
* Checks if the active user has the given permissions and throws a
* PermissionDeniedException if that isn't the case.
+ *
+ * @param array<string> $permissions list of permissions where each one must pass
+ * @throws PermissionDeniedException
*/
public function checkPermissions(array $permissions) {
foreach ($permissions as $permission) {
* Stores a new user object in this session, e.g. a user was guest because not
* logged in, after the login his old session is used to store his full data.
*
- * @param \wcf\data\userUser $user
+ * @param \wcf\data\user\User $user
* @param boolean $hideSession if true, database won't be updated
*/
public function changeUser(User $user, $hideSession = false) {
if (!$hideSession) {
// update session
+ /** @var \wcf\data\DatabaseObjectEditor $sessionEditor */
$sessionEditor = new $this->sessionEditorClassName($this->session);
$this->register('__changeSessionID', true);
* @param \wcf\data\user\User $user
*/
protected function changeUserVirtual(User $user) {
- $sessionTable = call_user_func(array($this->sessionClassName, 'getDatabaseTableName'));
+ /** @var \wcf\data\DatabaseObjectEditor $sessionEditor */
switch ($user->userID) {
//
}
// update session
+ /** @var \wcf\data\DatabaseObjectEditor $sessionEditor */
$sessionEditor = new $this->sessionEditorClassName($this->session);
$sessionEditor->update($data);
$this->disableUpdate();
// update last activity time
+ /** @var \wcf\data\DatabaseObjectEditor $sessionEditor */
$sessionEditor = new $this->sessionEditorClassName($this->session);
$sessionEditor->update(array(
'lastActivityTime' => TIME_NOW
$this->changeUser(new User(null));
// 2nd: Actually remove session
+ /** @var \wcf\data\DatabaseObjectEditor $sessionEditor */
$sessionEditor = new $this->sessionEditorClassName($this->session);
$sessionEditor->delete();
*/
public static function resetSessions(array $userIDs = array()) {
if (!empty($userIDs)) {
- UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);
- UserStorageHandler::getInstance()->reset($userIDs, 'languageIDs', 1);
+ UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs');
+ UserStorageHandler::getInstance()->reset($userIDs, 'languageIDs');
}
else {
- UserStorageHandler::getInstance()->resetAll('groupIDs', 1);
- UserStorageHandler::getInstance()->resetAll('languageIDs', 1);
+ UserStorageHandler::getInstance()->resetAll('groupIDs');
+ UserStorageHandler::getInstance()->resetAll('languageIDs');
}
}