Replace __construct() with __run() for all pages
authorAlexander Ebert <ebert@woltlab.com>
Tue, 5 Jun 2012 17:12:00 +0000 (19:12 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 5 Jun 2012 17:12:00 +0000 (19:12 +0200)
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).

wcfsetup/install/files/lib/action/AJAXProxyAction.class.php
wcfsetup/install/files/lib/action/AbstractAction.class.php
wcfsetup/install/files/lib/action/ClipboardAction.class.php
wcfsetup/install/files/lib/action/ClipboardProxyAction.class.php
wcfsetup/install/files/lib/action/IAction.class.php
wcfsetup/install/files/lib/page/AbstractPage.class.php
wcfsetup/install/files/lib/page/IPage.class.php
wcfsetup/install/files/lib/system/request/Request.class.php

index 1f6264ef8fca60a01d83800990600bd72efb2095..e59e7fc360fca47b0b9b931135998b1135362935 100644 (file)
@@ -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) {
index dab278c8687b59ebb80bc0f7d88fa5ac88d1c466..17264b99c566e57c49f5849f085823ff2cb6775b 100644 (file)
@@ -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();
index 5f547cfc571d34f6405209c48dbb1a4da7b65bf0..ba7e9a1874f6cc6087f161ed49d85b43aa927dfb 100644 (file)
@@ -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) {
index 336e5a80c5ba5770c20fb2a10a69342aaa95c370..9227d322088277518efcfbb2414ddf82a40aceab 100644 (file)
@@ -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) {
index 197783b5634549eefe63526cb13ef0f9e86860a7..751067f787bc684131e5e2cbda54ad3a10aef2ca 100644 (file)
@@ -13,6 +13,11 @@ namespace wcf\action;
  * @category   Community Framework
  */
 interface IAction {
+       /**
+        * Initializes this action.
+        */
+       public function __run();
+       
        /**
         * Reads the given parameters.
         */
index 7e38cb791c7b50e5ae76004e163f43fca0831343..85c4acee2d1035a4b6854f77e5f01da04bdbd78a 100644 (file)
@@ -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();
index 752f8d46e5ee4f117467481f4aca3f7c98c19642..8870223e373eb77ad0e987761cec422ea3ecfc86 100644 (file)
@@ -12,6 +12,11 @@ namespace wcf\page;
  * @category   Community Framework
  */
 interface IPage {
+       /**
+        * Initializes the page.
+        */
+       public function __run();
+       
        /**
         * Reads the given parameters.
         */
index a14a42e613a04c4095cb6cd4624afc194ba676ae..d52427d7ea6e5089a93ea338251dad9ac8d0768f 100644 (file)
@@ -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;
+       }
 }