jenkins-bot has submitted this change and it was merged.
Change subject: Allow callables in GatewayAdapter::$error_map
......................................................................
Allow callables in GatewayAdapter::$error_map
Cause sometimes you want to format a complicated error message
with parameters you don't even know when you defineErrorMap().
If the code maps to a callable, getErrorMapByCodeAndTranslate
returns whatever the callable returns.
Bug: T108123
Change-Id: I9f1f42bc6a8dc7c629e7c1645301dcebe05065a3
---
M gateway_common/gateway.adapter.php
1 file changed, 10 insertions(+), 4 deletions(-)
Approvals:
Cdentinger: Looks good to me, approved
jenkins-bot: Verified
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index 14254ba..59f6bf8 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -57,7 +57,7 @@
/**
* Define the message keys used to display errors to the user. Should
set
* @see $this->error_map to an array whose keys are error codes and
whose
- * values are i18n keys.
+ * values are i18n keys or callables that return a translated error
message.
* Any unmapped error code will use 'donate_interface-processing-error'
*/
function defineErrorMap();
@@ -203,11 +203,12 @@
/**
* $error_map maps gateway errors to client errors
*
- * The key of each error should map to a i18n message key.
+ * The key of each error should map to a i18n message key or a callable
* By convention, the following three keys have these meanings:
* 'internal-0000' => 'message-key-1', // Failed failed pre-process
checks.
* 'internal-0001' => 'message-key-2', // Transaction could not be
processed due to an internal error.
* 'internal-0002' => 'message-key-3', // Communication failure
+ * A callable should return the translated error message.
* Any undefined key will map to 'donate_interface-processing-error'
*
* @var array $error_map
@@ -713,10 +714,15 @@
$translatedMessage = '';
}
- // If the $code does not exist, use the default message
if ( isset( $this->error_map[ $code ] ) ) {
- $messageKey = $this->error_map[ $code ];
+ $mapped = $this->error_map[ $code ];
+ // Errors with complicated formatting can map to a
function
+ if ( is_callable( $mapped ) ) {
+ return $mapped();
+ }
+ $messageKey = $mapped;
} else {
+ // If the $code does not exist, use the default message
$messageKey = 'donate_interface-processing-error';
}
--
To view, visit https://gerrit.wikimedia.org/r/235293
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f1f42bc6a8dc7c629e7c1645301dcebe05065a3
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: amazon
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits