r102832 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102831‎ | r102832 | r102833 >
Date:00:43, 12 November 2011
Author:jpostlethwaite
Status:resolved (Comments)
Tags:fundraising 
Comment:
Added variable $this->dataConstraints. Added method $this->formatStagedData(). Added $this->formatStagedData() to $this->stageData(). This enhancement adds the ability to use data constraints which are handled in staging. Currently, all $this->staged_data, is trimmed and truncated if it is a string. See r102828, r102829.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -102,6 +102,17 @@
103103 abstract class GatewayAdapter implements GatewayType {
104104
105105 /**
 106+ * $dataConstraints provides information on how to handle variables.
 107+ *
 108+ * <code>
 109+ * 'account_holder' => array( 'type' => 'alphanumeric', 'length' => 50, )
 110+ * </code>
 111+ *
 112+ * @var array $dataConstraints
 113+ */
 114+ protected $dataConstraints = array();
 115+
 116+ /**
106117 * $error_map maps gateway errors to client errors
107118 *
108119 * The index of each error should map to a translation:
@@ -216,6 +227,7 @@
217228 $this->defineTransactions();
218229 $this->defineErrorMap();
219230 $this->defineVarMap();
 231+ $this->defineDataConstraints();
220232 $this->defineAccountInfo();
221233 $this->defineReturnValueMap();
222234
@@ -1509,7 +1521,7 @@
15101522 * @param type $type Whatever types of staging you feel like having in your child class.
15111523 * ...but usually request and response. I think.
15121524 */
1513 - function stageData( $type = 'request' ) {
 1525+ public function stageData( $type = 'request' ) {
15141526 $this->defineStagedVars();
15151527 $this->smooshVarsForStaging(); //yup, we do need to do this seperately.
15161528 //If we tried to piggyback off the same loop, all the vars wouldn't be ready, and some staging functions will require
@@ -1518,8 +1530,44 @@
15191531 $function_name = 'stage_' . $field;
15201532 $this->executeIfFunctionExists( $function_name, $type );
15211533 }
 1534+
 1535+ // Format the staged data
 1536+ $this->formatStagedData();
 1537+
15221538 }
15231539
 1540+ /**
 1541+ * Format staged data
 1542+ *
 1543+ * Formatting:
 1544+ * - trim - all strings
 1545+ * - truncate - all strings to the maximum length permitted by the gateway
 1546+ */
 1547+ public function formatStagedData() {
 1548+
 1549+ foreach ( $this->staged_data as $field => $value ) {
 1550+
 1551+ // Trim all values if they are a string
 1552+ $value = is_string( $value ) ? trim( $value ) : $value;
 1553+
 1554+ if ( isset( $this->dataConstraints[ $field ] ) && is_string( $value ) ) {
 1555+
 1556+ // Truncate the field if it has a length specified
 1557+ $length = isset( $this->dataConstraints[ $field ]['length']) ? (integer) $this->dataConstraints[ $field ]['length'] : false;
 1558+
 1559+ if ( !empty( $length ) && !empty( $value ) ) {
 1560+ $value = substr( $value, 0, $length );
 1561+ }
 1562+ }
 1563+ else {
 1564+
 1565+ $this->log( 'Field does not exist in $this->dataConstraints[ ' . ( string ) $field . ' ]', LOG_DEBUG );
 1566+ }
 1567+
 1568+ $this->staged_data[ $field ] = $value;
 1569+ }
 1570+ }
 1571+
15241572 function getPaypalRedirectURL() {
15251573 $currency = $this->getData_Raw( 'currency_code' );
15261574

Follow-up revisions

RevisionCommit summaryAuthorDate
r102835follow-up to r102832 - more readablekaldari01:01, 12 November 2011
r103847MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:30, 21 November 2011
r103848MFT r102338, r102681, r102685, r102810, r102828, r102829, r102832, r102836, r...khorn22:31, 21 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102828Implemented defineDataConstraints() for PayFlowPro. At this time, it is merel...jpostlethwaite00:28, 12 November 2011
r102829Reordered methods defineErrorMap() and defineDataConstraints() for code clean...jpostlethwaite00:31, 12 November 2011

Comments

#Comment by Kaldari (talk | contribs)   00:53, 12 November 2011

This looks good to me. Might want to have Katie double check it as well.

#Comment by Khorn (WMF) (talk | contribs)   21:30, 21 November 2011

r103246: I had to wrap that call to formatStagedData in a test to see if it was request staging or not. We only want to truncate the outgoing, and stageData is supposed to work both on both incoming and outgoing.

Also, stageData probably shouldn't be public, as double-staging the data could cause all kinds of problems that might not be readily apparent. ...like multiplying the amount by an unintentional extra hundred.

#Comment by Khorn (WMF) (talk | contribs)   21:34, 21 November 2011

Changed to protected in r103839.

Status & tagging log