Awight has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300804

Change subject: [WIP] Some decoupling of GatewayPage from GatewayType
......................................................................

[WIP] Some decoupling of GatewayPage from GatewayType

GatewayType is no longer responsible for the HTTP context or request.

Bug: T131798
Bug: T131275
Change-Id: Iae8d4499ee73ce521985ba9277e93457b5b924df
---
M gateway_common/GatewayPage.php
M gateway_common/GatewayType.php
M gateway_common/gateway.adapter.php
M gateway_forms/Form.php
M gateway_forms/Mustache.php
5 files changed, 27 insertions(+), 40 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/04/300804/1

diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index b99f253..66ef22e 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -160,7 +160,9 @@
                $form_class = $this->adapter->getFormClass();
                // TODO: use interface.  static ctor.
                if ( $form_class && class_exists( $form_class ) ){
-                       $form_obj = new $form_class( $this->adapter );
+                       $form_obj = new $form_class();
+                       $form_obj->setGateway( $this->adapter );
+                       $form_obj->setGatewayPage( $this );
                        $form = $form_obj->getForm();
                        $output->addModules( $form_obj->getResources() );
                        $output->addModuleStyles( $form_obj->getStyleModules() 
);
diff --git a/gateway_common/GatewayType.php b/gateway_common/GatewayType.php
index 24a758a..7ebe8a9 100644
--- a/gateway_common/GatewayType.php
+++ b/gateway_common/GatewayType.php
@@ -283,13 +283,6 @@
        public function setRiskScore( $score );
 
        /**
-        * Get the current HTTP request
-        *
-        * @return WebRequest
-        */
-       public function getRequest();
-
-       /**
         * Returns the current validation action.
         * This will typically get set and altered by the various enabled 
process hooks.
         *
diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index 5355011..42b6ded 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -178,12 +178,6 @@
        protected $api_request = false;
 
        /**
-        * The current HTTP request context
-        * @var IContextSource
-        */
-       protected $context;
-
-       /**
         * The current HTTP request
         * @var WebRequest
         */
@@ -227,8 +221,6 @@
         * @see DonationData
         */
        public function __construct( $options = array() ) {
-               $this->context = RequestContext::getMain();
-               $this->request = $this->context->getRequest();
 
                $defaults = array(
                        'external_data' => null,
@@ -261,7 +253,9 @@
 
                $this->defineDataTransformers();
 
-               $this->session_resetOnSwitch(); // Need to do this before 
creating DonationData
+               if ( !$this->isBatchProcessor() ) {
+                       $this->session_resetOnSwitch(); // Need to do this 
before creating DonationData
+               }
 
                // FIXME: this should not have side effects like setting 
order_id_meta['final']
                $this->dataObj = new DonationData( $this, 
$options['external_data'] );
@@ -292,18 +286,6 @@
                        ) );
                        $this->addManualError( $error );
                }
-       }
-
-       /**
-        * Get the currency HTTP request context
-        * @return IContextSource
-        */
-       public function getContext() {
-               return $this->context;
-       }
-
-       public function getRequest() {
-               return $this->request;
        }
 
        /**
diff --git a/gateway_forms/Form.php b/gateway_forms/Form.php
index d088c2c..557bc44 100644
--- a/gateway_forms/Form.php
+++ b/gateway_forms/Form.php
@@ -19,6 +19,11 @@
        protected $gateway;
 
        /**
+        * @var GatewayPage
+        */
+       protected $gatewayPage;
+
+       /**
         * @var string
         */
        protected $scriptPath;
@@ -34,10 +39,13 @@
         */
        abstract function getForm();
 
-       public function __construct( $gateway ) {
+       /**
+        * Get these objects using "new" with no parameters.
+        */
+       public function __construct() {}
 
+       public function setGateway( GatewayType $gateway ) {
                $this->gateway = $gateway;
-               $this->scriptPath = 
$this->gateway->getContext()->getConfig()->get( 'ScriptPath' );
                $this->logger = DonationLoggerFactory::getLogger( $gateway );
                $gateway_errors = $this->gateway->getAllErrors();
 
@@ -50,11 +58,16 @@
                $this->form_errors = array_merge( 
DataValidator::getEmptyErrorArray(), $gateway_errors );
        }
 
+       public function setGatewayPage( GatewayPage $gatewayPage ) {
+               $this->gatewayPage = $gatewayPage;
+               $this->scriptPath = 
$gatewayPage->getContext()->getConfig()->get( 'ScriptPath' );
+       }
+
        /**
         * Uses resource loader to load the form validation javascript.
         */
        protected function loadValidateJs() {
-               $this->gateway->getContext()->getOutput()->addModules( 
'di.form.core.validate' );
+               $this->gatewayPage->getContext()->getOutput()->addModules( 
'di.form.core.validate' );
        }
 
        /**
@@ -120,7 +133,7 @@
                }
 
                // construct the submission url
-               $title = $this->gateway->getContext()->getTitle();
+               $title = $this->gatewayPage->getContext()->getTitle();
                return wfAppendQuery( $title->getLocalURL(), $query_array );
        }
 
diff --git a/gateway_forms/Mustache.php b/gateway_forms/Mustache.php
index baca62d..5abf671 100644
--- a/gateway_forms/Mustache.php
+++ b/gateway_forms/Mustache.php
@@ -18,13 +18,10 @@
 
        public static $baseDir;
 
-       /**
-        * @param GatewayAdapter $gateway The live adapter object that is used 
as
-        * the source for donor data and capabilities discovery.
-        */
-       public function __construct( GatewayAdapter $gateway ) {
-               parent::__construct( $gateway );
+       public function setGateway( GatewayType $gateway ) {
+               parent::setGateway( $gateway );
 
+               // FIXME: late binding fail?
                self::$baseDir = dirname( $this->getTopLevelTemplate() );
        }
 
@@ -98,7 +95,7 @@
 
        protected function getData() {
                $data = $this->gateway->getData_Unstaged_Escaped();
-               $output = $this->gateway->getContext()->getOutput();
+               $output = $this->gatewayPage->getContext()->getOutput();
 
                $data['script_path'] = $this->scriptPath;
                $data['verisign_logo'] = $this->getSmallSecureLogo();

-- 
To view, visit https://gerrit.wikimedia.org/r/300804
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae8d4499ee73ce521985ba9277e93457b5b924df
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <awi...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to