* @category Community Framework
*/
abstract class TreeMenu extends SingletonFactory {
- /**
- * @var EventHandler
- */
- protected $eventHandler;
-
/**
* list of visible menu items
* @var array<\wcf\system\menu\ITreeMenuItem>
*/
public $menuItems = null;
- /**
- * TreeMenu constructor.
- *
- * @param EventHandler $eventHandler
- */
- public function __construct(EventHandler $eventHandler) {
- $this->eventHandler = $eventHandler;
-
- parent::__construct();
- }
-
/**
* @see \wcf\system\SingletonFactory::init()
*/
$this->buildMenuItemList();
// call init event
- $this->eventHandler->fireAction($this, 'init');
+ EventHandler::getInstance()->fireAction($this, 'init');
}
/**
*/
protected function loadCache() {
// call loadCache event
- $this->eventHandler->fireAction($this, 'loadCache');
+ EventHandler::getInstance()->fireAction($this, 'loadCache');
$this->menuItems = array();
}
* @category Community Framework
*/
class ACPMenu extends TreeMenu {
- /**
- * @var ACPMenuCacheBuilder
- */
- protected $acpMenuCacheBuilder;
-
- /**
- * ACPMenu constructor.
- *
- * @param ACPMenuCacheBuilder $acpMenuCacheBuilder
- * @param EventHandler $eventHandler
- */
- public function __construct(ACPMenuCacheBuilder $acpMenuCacheBuilder, EventHandler $eventHandler) {
- $this->acpMenuCacheBuilder = $acpMenuCacheBuilder;
-
- parent::__construct($eventHandler);
- }
-
/**
* @see TreeMenu::loadCache()
*/
return;
}
- $this->menuItems = $this->acpMenuCacheBuilder->getData();
+ $this->menuItems = ACPMenuCacheBuilder::getInstance()->getData();
}
}
*/
protected $landingPage = null;
- /**
- * @var PageMenuCacheBuilder
- */
- protected $pageMenuCacheBuilder;
-
- /**
- * PageMenu constructor.
- *
- * @param EventHandler $eventHandler
- * @param PageMenuCacheBuilder $pageMenuCacheBuilder
- */
- public function __construct(EventHandler $eventHandler, PageMenuCacheBuilder $pageMenuCacheBuilder) {
- $this->pageMenuCacheBuilder = $pageMenuCacheBuilder;
-
- parent::__construct($eventHandler);
- }
-
/**
* @see \wcf\system\SingletonFactory::init()
* @throws SystemException
$this->buildMenuItemList('footer');
// call init event
- $this->eventHandler->fireAction($this, 'init');
+ EventHandler::getInstance()->fireAction($this, 'init');
foreach ($this->menuItems as $menuItems) {
foreach ($menuItems as $menuItem) {
parent::loadCache();
// get cache
- $this->menuItems = $this->pageMenuCacheBuilder->getData();
+ $this->menuItems = PageMenuCacheBuilder::getInstance()->getData();
}
/**
* @category Community Framework
*/
class UserMenu extends TreeMenu {
- /**
- * @var UserMenuCacheBuilder
- */
- protected $userMenuCacheBuilder;
-
- /**
- * UserMenu constructor.
- *
- * @param EventHandler $eventHandler
- * @param UserMenuCacheBuilder $userMenuCacheBuilder
- */
- public function __construct(EventHandler $eventHandler, UserMenuCacheBuilder $userMenuCacheBuilder) {
- $this->userMenuCacheBuilder = $userMenuCacheBuilder;
-
- parent::__construct($eventHandler);
- }
-
/**
* @see TreeMenu::loadCache()
*/
protected function loadCache() {
parent::loadCache();
- $this->menuItems = $this->userMenuCacheBuilder->getData();
+ $this->menuItems = UserMenuCacheBuilder::getInstance()->getData();
}
/**
*/
public $activeMenuItem = null;
- /**
- * @var EventHandler
- */
- protected $eventHandler;
-
/**
* list of all menu items
* @var UserProfileMenuItem[]
*/
public $menuItems = null;
- /**
- * @var UserProfileMenuCacheBuilder
- */
- protected $userProfileMenuCacheBuilder;
-
- /**
- * UserProfileMenu constructor.
- *
- * @param EventHandler $eventHandler
- * @param UserProfileMenuCacheBuilder $userProfileMenuCacheBuilder
- */
- public function __construct(EventHandler $eventHandler, UserProfileMenuCacheBuilder $userProfileMenuCacheBuilder) {
- $this->eventHandler = $eventHandler;
- $this->userProfileMenuCacheBuilder = $userProfileMenuCacheBuilder;
-
- parent::__construct();
- }
-
/**
* @see \wcf\system\SingletonFactory::init()
*/
$this->checkMenuItems();
// call init event
- $this->eventHandler->fireAction($this, 'init');
+ EventHandler::getInstance()->fireAction($this, 'init');
}
/**
*/
protected function loadCache() {
// call loadCache event
- $this->eventHandler->fireAction($this, 'loadCache');
+ EventHandler::getInstance()->fireAction($this, 'loadCache');
- $this->menuItems = $this->userProfileMenuCacheBuilder->getData();
+ $this->menuItems = UserProfileMenuCacheBuilder::getInstance()->getData();
}
/**
public function handle($application = 'wcf', $isACPRequest = false) {
$this->isACPRequest = $isACPRequest;
- if (!RouteHandler::getInstance()->matches($application)) {
+ if (!RouteHandler::getInstance()->matches()) {
if (ENABLE_DEBUG_MODE) {
throw new SystemException("Cannot handle request, no valid route provided.");
}
use wcf\system\event\EventHandler;
use wcf\system\exception\SystemException;
use wcf\system\request\route\DynamicRequestRoute;
-use wcf\system\request\route\IRequestRoute;
+use wcf\system\request\route\LookupRequestRoute;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
use wcf\util\FileUtil;
$this->addRoute($route);
$route = new DynamicRequestRoute();
- $route->setIsACP(false);
+ $this->addRoute($route);
+
+ $route = new LookupRequestRoute();
$this->addRoute($route);
// fire event
* first route that is able to consume all path components is used,
* even if other routes may fit better. Route order is crucial!
*
- * @param string $application application identifier
* @return boolean
*/
- public function matches($application) {
+ public function matches() {
foreach ($this->routes as $route) {
- if ($this->requestHandler->isACPRequest() != $route->isACP()) {
+ if (RequestHandler::getInstance()->isACPRequest() != $route->isACP()) {
continue;
}
- $match = false;
- if ($route instanceof IRequestRoute) {
- $match = $route->matches($application, self::getPathInfo());
- }
- else if ($route instanceof IRoute) {
- // legacy route
- $match = $route->matches(self::getPathInfo());
- }
-
- if ($match) {
+ if ($route->matches(self::getPathInfo())) {
$this->routeData = $route->getRouteData();
$this->isDefaultController = $this->routeData['isDefaultController'];
* @throws SystemException
*/
public function buildRoute(array $components, $isACP = null) {
- if ($isACP === null) $isACP = $this->requestHandler->isACPRequest();
+ if ($isACP === null) $isACP = RequestHandler::getInstance()->isACPRequest();
foreach ($this->routes as $route) {
if ($isACP != $route->isACP()) {
*/
protected $routeData = [];
+ /**
+ * DynamicRequestRoute constructor.
+ */
+ public function __construct() {
+ $this->init();
+ }
+
/**
* Sets default routing information.
*/
/**
* @see IRoute::matches()
*/
- public function matches($application, $requestURL) {
+ public function matches($requestURL) {
if (preg_match($this->pattern, $requestURL, $matches)) {
foreach ($matches as $key => $value) {
if (!is_numeric($key)) {
* @subpackage system.request
* @category Community Framework
*/
-interface IRequestRoute {
- /**
- * Builds a link upon route components.
- *
- * @param array $components list of url components
- * @return string
- */
- public function buildLink(array $components);
-
- /**
- * Returns true if current route can handle the build request.
- *
- * @param array $components list of url components
- * @return boolean
- */
- public function canHandle(array $components);
-
- /**
- * Returns parsed route data.
- *
- * @return array
- */
- public function getRouteData();
-
- /**
- * Returns true if route applies for ACP.
- *
- * @return boolean
- */
- public function isACP();
-
- /**
- * Returns true if given request url matches this route.
- *
- * @param string $application application identifier
- * @param string $requestURL request url
- * @return boolean
- */
- public function matches($application, $requestURL);
-
+interface IRequestRoute extends IRoute {
/**
* Configures this route to handle either ACP or frontend requests.
*
<?php
namespace wcf\system\request\route;
-
+use wcf\system\application\ApplicationHandler;
use wcf\system\exception\SystemException;
use wcf\system\request\ControllerMap;
use wcf\util\FileUtil;
+/**
+ * Attempts to resolve arbitrary request URLs against the list of known custom
+ * controller URLs, optionally recognizing id and title parameter.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2015 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system.request
+ * @category Community Framework
+ */
class LookupRequestRoute implements IRequestRoute {
+ /**
+ * list of parsed route information
+ * @var array
+ */
protected $routeData = [];
/**
* @inheritDoc
*/
- public function matches($application, $requestURL) {
+ public function matches($requestURL) {
$requestURL = FileUtil::addLeadingSlash($requestURL);
if ($requestURL === '/') {
$~x';
if (preg_match($regex, $requestURL, $matches)) {
+ $application = ApplicationHandler::getInstance()->getActiveApplication()->getAbbreviation();
if (!empty($matches['id'])) {
// check for static controller URLs
$this->routeData = ControllerMap::getInstance()->resolveCustomController($application, $matches['controller']);
/**
* @see \wcf\system\request\IRoute::matches()
*/
- public function matches($application, $requestURL) {
- if (parent::matches($application, $requestURL)) {
+ public function matches($requestURL) {
+ if (parent::matches($requestURL)) {
$this->routeData['application'] = $this->staticApplication;
$this->routeData['controller'] = ControllerMap::getInstance()->lookup($this->staticController);
$this->routeData['isDefaultController'] = false;
*/
public function hasValidCookie() {
if (isset($_COOKIE[COOKIE_PREFIX.'cookieHash'])) {
- if ($_COOKIE[COOKIE_PREFIX.'cookieHash'] == $this->sessionHandler->sessionID) {
+ if ($_COOKIE[COOKIE_PREFIX.'cookieHash'] == SessionHandler::getInstance()->sessionID) {
return true;
}
}
protected function init() {
if (!$this->hasValidCookie()) {
// cookie support will be enabled upon next request
- HeaderUtil::setCookie('cookieHash', $this->sessionHandler->sessionID);
+ HeaderUtil::setCookie('cookieHash', SessionHandler::getInstance()->sessionID);
}
// enable cookie support
- $this->sessionHandler->enableCookies();
+
+ SessionHandler::getInstance()->enableCookies();
parent::init();
}