From 8f1ba4d230880bbe1424ceb98a511ba871b40caa Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 5 Jun 2012 19:12:00 +0200 Subject: [PATCH] Replace __construct() with __run() for all pages Initialization no longer takes place within __construct(), instead all logic is moved into __run(). This way you can access the current request object via RequestHandler::getInstance()->getActiveRequest()->getRequestObject(), but beware it isn't fully initialized yet (as the __run() is active while you access the object itself). --- .../lib/action/AJAXProxyAction.class.php | 6 ++--- .../files/lib/action/AbstractAction.class.php | 5 ++-- .../lib/action/ClipboardAction.class.php | 6 ++--- .../lib/action/ClipboardProxyAction.class.php | 6 ++--- .../files/lib/action/IAction.class.php | 5 ++++ .../files/lib/page/AbstractPage.class.php | 5 ++-- .../install/files/lib/page/IPage.class.php | 5 ++++ .../lib/system/request/Request.class.php | 23 +++++++++++++------ 8 files changed, 39 insertions(+), 22 deletions(-) diff --git a/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php b/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php index 1f6264ef8f..e59e7fc360 100644 --- a/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXProxyAction.class.php @@ -63,11 +63,11 @@ class AJAXProxyAction extends AbstractSecureAction { protected $response = null; /** - * @see wcf\action\AbstractAction::_construct() + * @see wcf\action\IAction::__run() */ - public function __construct() { + public function __run() { try { - parent::__construct(); + parent::__run(); } catch (\Exception $e) { if ($e instanceof AJAXException) { diff --git a/wcfsetup/install/files/lib/action/AbstractAction.class.php b/wcfsetup/install/files/lib/action/AbstractAction.class.php index dab278c868..17264b99c5 100644 --- a/wcfsetup/install/files/lib/action/AbstractAction.class.php +++ b/wcfsetup/install/files/lib/action/AbstractAction.class.php @@ -29,10 +29,9 @@ abstract class AbstractAction implements IAction { public $neededPermissions = array(); /** - * Creates a new AbstractAction object. - * Calls the methods readParameters() and execute() automatically. + * @see wcf\action\IAction::__run() */ - public function __construct() { + public function __run() { // call default methods $this->readParameters(); $this->execute(); diff --git a/wcfsetup/install/files/lib/action/ClipboardAction.class.php b/wcfsetup/install/files/lib/action/ClipboardAction.class.php index 5f547cfc57..ba7e9a1874 100644 --- a/wcfsetup/install/files/lib/action/ClipboardAction.class.php +++ b/wcfsetup/install/files/lib/action/ClipboardAction.class.php @@ -55,11 +55,11 @@ class ClipboardAction extends AbstractSecureAction { protected $objectTypeID = 0; /** - * @see wcf\action\AbstractAction::_construct() + * @see wcf\action\IAction::__run() */ - public function __construct() { + public function __run() { try { - parent::__construct(); + parent::__run(); } catch (\Exception $e) { if ($e instanceof AJAXException) { diff --git a/wcfsetup/install/files/lib/action/ClipboardProxyAction.class.php b/wcfsetup/install/files/lib/action/ClipboardProxyAction.class.php index 336e5a80c5..9227d32208 100644 --- a/wcfsetup/install/files/lib/action/ClipboardProxyAction.class.php +++ b/wcfsetup/install/files/lib/action/ClipboardProxyAction.class.php @@ -37,11 +37,11 @@ class ClipboardProxyAction extends AbstractSecureAction { protected $typeName = ''; /** - * @see wcf\action\AbstractAction::_construct() + * @see wcf\action\IAction::__run() */ - public function __construct() { + public function __run() { try { - parent::__construct(); + parent::__run(); } catch (\Exception $e) { if ($e instanceof AJAXException) { diff --git a/wcfsetup/install/files/lib/action/IAction.class.php b/wcfsetup/install/files/lib/action/IAction.class.php index 197783b563..751067f787 100644 --- a/wcfsetup/install/files/lib/action/IAction.class.php +++ b/wcfsetup/install/files/lib/action/IAction.class.php @@ -13,6 +13,11 @@ namespace wcf\action; * @category Community Framework */ interface IAction { + /** + * Initializes this action. + */ + public function __run(); + /** * Reads the given parameters. */ diff --git a/wcfsetup/install/files/lib/page/AbstractPage.class.php b/wcfsetup/install/files/lib/page/AbstractPage.class.php index 7e38cb791c..85c4acee2d 100644 --- a/wcfsetup/install/files/lib/page/AbstractPage.class.php +++ b/wcfsetup/install/files/lib/page/AbstractPage.class.php @@ -48,10 +48,9 @@ abstract class AbstractPage implements IPage { public $neededPermissions = array(); /** - * Creates a new AbstractPage object. - * Calls the readParameters() and show() methods automatically. + * @see wcf\page\IPage::__run() */ - public function __construct() { + public function __run() { // call default methods $this->readParameters(); $this->show(); diff --git a/wcfsetup/install/files/lib/page/IPage.class.php b/wcfsetup/install/files/lib/page/IPage.class.php index 752f8d46e5..8870223e37 100644 --- a/wcfsetup/install/files/lib/page/IPage.class.php +++ b/wcfsetup/install/files/lib/page/IPage.class.php @@ -12,6 +12,11 @@ namespace wcf\page; * @category Community Framework */ interface IPage { + /** + * Initializes the page. + */ + public function __run(); + /** * Reads the given parameters. */ diff --git a/wcfsetup/install/files/lib/system/request/Request.class.php b/wcfsetup/install/files/lib/system/request/Request.class.php index a14a42e613..d52427d7ea 100644 --- a/wcfsetup/install/files/lib/system/request/Request.class.php +++ b/wcfsetup/install/files/lib/system/request/Request.class.php @@ -31,10 +31,10 @@ class Request { protected $pageType = ''; /** - * true, if this request has already been executed - * @var boolean + * request object + * @var object */ - protected $executed = false; + protected $requestObject = null; /** * Creates a new request object. @@ -53,9 +53,9 @@ class Request { * Executes this request. */ public function execute() { - if (!$this->executed) { - $this->executed = true; - new $this->className(); + if ($this->requestObject === null) { + $this->requestObject = new $this->className(); + $this->requestObject->__run(); } } @@ -65,7 +65,7 @@ class Request { * @return boolean */ public function isExecuted() { - return $this->executed; + return ($this->requestObject !== null); } /** @@ -94,4 +94,13 @@ class Request { public function getPageType() { return $this->pageType; } + + /** + * Returns the current request object. + * + * @return object + */ + public function getRequestObject() { + return $this->requestObject; + } } -- 2.20.1