Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/355577 )
Change subject: WIP actually split out config classes ...................................................................... WIP actually split out config classes Change-Id: Ib5c810b0fd08e8c0147aaac1f75dda018f9723d2 --- M Core/Configuration.php M Core/Context.php M Core/DataStores/QueueWrapper.php M Core/DataStores/SmashPigDatabase.php A Core/GlobalConfiguration.php M Core/Http/CurlWrapper.php M Core/Http/OutboundRequest.php M Core/Listeners/ListenerBase.php M Core/Logging/LogStreams/FailmailLogStream.php M Core/MailHandler.php M Core/Messages/ListenerMessage.php A Core/ProviderConfiguration.php M Core/QueueConsumers/BaseQueueConsumer.php M Maintenance/CreateIpnMessagesFromPendingDb.php M Maintenance/DumpConfig.php M Maintenance/MaintenanceBase.php M Maintenance/doMaintenance.php M PaymentProviders/Adyen/AdyenPaymentsAPI.php M PaymentProviders/Adyen/Jobs/DownloadReportJob.php M PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php M PaymentProviders/Amazon/Actions/CloseOrderReference.php M PaymentProviders/Amazon/AmazonApi.php M PaymentProviders/Amazon/Audit/AuditParser.php M PaymentProviders/Amazon/Audit/ReportDownloader.php M PaymentProviders/Ingenico/Api.php M PaymentProviders/Ingenico/BankPaymentProvider.php M PaymentProviders/Ingenico/IdealStatusProvider.php M PaymentProviders/Ingenico/IngenicoPaymentProvider.php M PaymentProviders/PayPal/Job.php M PaymentProviders/PayPal/Listener.php M PaymentProviders/PayPal/Message.php M PaymentProviders/PayPal/PayPalPaymentsAPI.php M PaymentProviders/PaymentProviderFactory.php M config/main.yaml 34 files changed, 244 insertions(+), 180 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig refs/changes/77/355577/1 diff --git a/Core/Configuration.php b/Core/Configuration.php index 89406de..d93223d 100644 --- a/Core/Configuration.php +++ b/Core/Configuration.php @@ -6,7 +6,7 @@ /** * Cascading configuration using YAML files */ -class Configuration { +abstract class Configuration { /** @var array K/V array of configuration options for the initialized node */ protected $options = array(); @@ -14,81 +14,13 @@ /** @var array keyed on class name that stores persistent objects */ protected $objects = array(); - /** - * @var string Name of the view that generated this configuration object - * - * FIXME: There's still something fishy about view. - */ - protected $viewName = 'default'; - - /** - * Creates a configuration object for a specific configuration node. - * - * @param string $view Configuration view to load - * FIXME: No reason to provide a default. - * - * @return Configuration or subclass - */ - public static function createForView( $view = 'default' ) { - $config = new static(); - $config->viewName = $view; - $config->loadDefaultConfig(); - - return $config; - } - - /** - * Creates a configuration object for a specific configuration node. - * - * FIXME: Don't provide defaults once usages are cleaned up. - * - * @param string $view Configuration view to load - * @param array|string|null $overridePath Extra configuration path(s) to search - * - * @return Configuration or subclass - */ - public static function createForViewWithOverrideFile( $view = 'default', $overridePath = null ) { - $config = new static(); - $config->viewName = $view; - - if ( !$overridePath ) { - $config->loadDefaultConfig(); - } else { - $searchPath = array_merge( - ( array ) $overridePath, - $config->getDefaultSearchPath() - ); - $config->loadConfigFromPaths( $searchPath ); - } - return $config; - } - public function loadDefaultConfig() { $this->loadConfigFromPaths( $this->getDefaultSearchPath() ); } - public function getDefaultSearchPath() { - $searchPath = array(); + abstract public function getDefaultSearchPath(); - // FIXME: The whole 'view' thing is going to go away when we split into - // GlobalConfiguration and ProviderConfiguration - if ( $this->viewName !== 'default' ) { - - if ( isset( $_SERVER['HOME'] ) ) { - $searchPath[] = "{$_SERVER['HOME']}/.smashpig/{$this->viewName}/main.yaml"; - } - $searchPath[] = "/etc/smashpig/{$this->viewName}/main.yaml"; - $searchPath[] = __DIR__ . "/../config/{$this->viewName}/main.yaml"; - } - - if ( isset( $_SERVER['HOME'] ) ) { - // FIXME: But I don't understand why this key is missing during testing. - $searchPath[] = "{$_SERVER['HOME']}/.smashpig/main.yaml"; - } - $searchPath[] = '/etc/smashpig/main.yaml'; - $searchPath[] = __DIR__ . '/../config/main.yaml'; - return $searchPath; - } + abstract public function getDefaultOptions(); /** * Load a search path consisting of single files or globs @@ -103,7 +35,7 @@ $paths = $this->expandSearchPathToActual( $searchPath ); // Reset to empty set. - $this->options = array(); + $this->options = $this->getDefaultOptions(); // Attempt to load the configuration files from disk $configs = array(); @@ -283,13 +215,6 @@ } catch ( ConfigurationKeyException $ex ) { return false; } - } - - /** - * @return string The name of the view used to generate this configuration object - */ - public function getViewName() { - return $this->viewName; } /** diff --git a/Core/Context.php b/Core/Context.php index 163a9ab..0405902 100644 --- a/Core/Context.php +++ b/Core/Context.php @@ -17,19 +17,31 @@ protected $sourceRevision = 'unknown'; protected $sourceName = 'SmashPig'; protected $sourceType = 'listener'; + const NO_PROVIDER = 'no_provider'; - /** @var Configuration|null Reference to the context configuration object */ - protected $config = null; + /** @var GlobalConfiguration|null Reference to the global configuration object */ + protected $globalConfiguration = null; - public static function init( Configuration $config ) { + /** @var array associate array of ProviderConfiguration objects */ + protected $providerConfigurations = array(); + + protected $currentProvider = self::NO_PROVIDER; + + public static function init( GlobalConfiguration $config ) { if ( !Context::$instance ) { Context::$instance = new Context(); - Context::$instance->setConfiguration( $config ); + Context::$instance->setGlobalConfiguration( $config ); + $nullProviderConfiguration = ProviderConfiguration::createDefault( + $config->val( 'provider-defaults' ) + ); + Context::$instance->setProviderConfiguration( + Context::NO_PROVIDER, $nullProviderConfiguration + ); } } public static function initWithLogger( - Configuration $config, + GlobalConfiguration $config, $loggerPrefix = '' ) { self::init( $config ); @@ -107,21 +119,47 @@ * based on account; this will somehow require us to support either * stacked configurations or stacked contexts... * - * @param Configuration $config + * @param GlobalConfiguration $config */ - protected function setConfiguration( Configuration $config ) { - $this->config = $config; + protected function setGlobalConfiguration( GlobalConfiguration $config ) { + $this->globalConfiguration = $config; } /** - * Gets the configuration object associated with the current context. + * Gets the global configuration object associated with the current context. * - * Set the configuration using init() + * Set the global configuration using init() * - * @return null|Configuration + * @return null|GlobalConfiguration */ - public function getConfiguration() { - return $this->config; + public function getGlobalConfiguration() { + return $this->globalConfiguration; + } + + /** + * @return string + */ + public function getCurrentProvider() { + return $this->currentProvider; + } + + /** + * @param string $provider + */ + public function setCurrentProvider( $provider ) { + // FIXME: need to ensure there's always a matching configuration + $this->currentProvider = $provider; + } + + /** + * @return ProviderConfiguration + */ + public function getCurrentProviderConfiguration() { + return $this->providerConfigurations[$this->currentProvider]; + } + + public function setProviderConfiguration( $provider, ProviderConfiguration $configuration ) { + $this->providerConfigurations[$provider] = $configuration; } /** diff --git a/Core/DataStores/QueueWrapper.php b/Core/DataStores/QueueWrapper.php index 4b71e25..ac504f6 100644 --- a/Core/DataStores/QueueWrapper.php +++ b/Core/DataStores/QueueWrapper.php @@ -26,7 +26,7 @@ * @return FifoQueueStore */ public static function getQueue( $queueName ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $key = "data-store/$queueName"; // Examine the config node for a queue name diff --git a/Core/DataStores/SmashPigDatabase.php b/Core/DataStores/SmashPigDatabase.php index ad8c9b7..3ed79c2 100644 --- a/Core/DataStores/SmashPigDatabase.php +++ b/Core/DataStores/SmashPigDatabase.php @@ -21,7 +21,7 @@ protected static $dbs = array(); protected function __construct() { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); if ( !$this->getDatabase() ) { $this->setDatabase( $config->object( $this->getConfigKey() ) ); } diff --git a/Core/GlobalConfiguration.php b/Core/GlobalConfiguration.php new file mode 100644 index 0000000..40651bc --- /dev/null +++ b/Core/GlobalConfiguration.php @@ -0,0 +1,58 @@ +<?php +namespace SmashPig\Core; + +/** + * Cascading configuration using YAML files + */ +class GlobalConfiguration extends Configuration { + + /** + * Creates a GlobalConfiguration object + * + * @return GlobalConfiguration + */ + public static function create() { + $config = new static(); + $config->loadDefaultConfig(); + + return $config; + } + + /** + * Creates a configuration object, overriding values from files. + * + * @param array|string $overridePath Extra configuration path(s) to search + * + * @return Configuration or subclass + */ + public static function createWithOverrideFile( $overridePath ) { + $config = new static(); + + if ( !$overridePath ) { + $config->loadDefaultConfig(); + } else { + $searchPath = array_merge( + ( array ) $overridePath, + $config->getDefaultSearchPath() + ); + $config->loadConfigFromPaths( $searchPath ); + } + return $config; + } + + public function getDefaultSearchPath() { + $searchPath = array(); + + if ( isset( $_SERVER['HOME'] ) ) { + // FIXME: But I don't understand why this key is missing during testing. + $searchPath[] = "{$_SERVER['HOME']}/.smashpig/main.yaml"; + } + $searchPath[] = '/etc/smashpig/main.yaml'; + $searchPath[] = __DIR__ . '/../config/main.yaml'; + return $searchPath; + } + + public function getDefaultOptions() { + return array(); + } +} diff --git a/Core/Http/CurlWrapper.php b/Core/Http/CurlWrapper.php index c39cc59..d1505d5 100644 --- a/Core/Http/CurlWrapper.php +++ b/Core/Http/CurlWrapper.php @@ -14,7 +14,7 @@ protected $configuration; public function __construct() { - $this->configuration = Context::get()->getConfiguration(); + $this->configuration = Context::get()->getGlobalConfiguration(); } public function execute( $url, $method, $responseHeaders, $data ) { diff --git a/Core/Http/OutboundRequest.php b/Core/Http/OutboundRequest.php index 8eeb187..fe2c713 100644 --- a/Core/Http/OutboundRequest.php +++ b/Core/Http/OutboundRequest.php @@ -71,7 +71,7 @@ } public function execute() { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $wrapper = $config->object( 'curl/wrapper' ); return $wrapper->execute( $this->url, diff --git a/Core/Listeners/ListenerBase.php b/Core/Listeners/ListenerBase.php index fb49b66..88168ac 100644 --- a/Core/Listeners/ListenerBase.php +++ b/Core/Listeners/ListenerBase.php @@ -20,7 +20,7 @@ protected $c; public function __construct() { - $this->c = Context::get()->getConfiguration(); + $this->c = Context::get()->getGlobalConfiguration(); } public function execute( Request $request, Response $response ) { diff --git a/Core/Logging/LogStreams/FailmailLogStream.php b/Core/Logging/LogStreams/FailmailLogStream.php index fb74243..2f72fd9 100644 --- a/Core/Logging/LogStreams/FailmailLogStream.php +++ b/Core/Logging/LogStreams/FailmailLogStream.php @@ -153,7 +153,7 @@ $level = 'ERROR'; } - $currentView = Context::get()->getConfiguration()->getViewName(); + $currentView = Context::get()->getGlobalConfiguration()->getViewName(); MailHandler::sendEmail( $this->to, diff --git a/Core/MailHandler.php b/Core/MailHandler.php index f427cc7..0f99104 100644 --- a/Core/MailHandler.php +++ b/Core/MailHandler.php @@ -4,9 +4,7 @@ /** * Abstraction on top of whatever email client we're actually using. For the moment that's - * PHPMailer on top of sendmail. The PHPMailer library must be in the include path. Use the - * configuration node 'include-paths' to do this. - * FIXME: should be more explicit, phpmailer-include-path or something + * PHPMailer on top of sendmail, pulled in via Composer. */ class MailHandler { @@ -56,7 +54,7 @@ public static function sendEmail( $to, $subject, $textBody, $from = null, $replyTo = null, $htmlBody = null, $attach = array(), $cc = null, $bcc = null, $useVerp = true ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $mailer = static::mailbaseFactory(); try { diff --git a/Core/Messages/ListenerMessage.php b/Core/Messages/ListenerMessage.php index 740138a..d8c522c 100644 --- a/Core/Messages/ListenerMessage.php +++ b/Core/Messages/ListenerMessage.php @@ -31,7 +31,7 @@ $retval = true; // TODO: Cache this? - $actions = Context::get()->getConfiguration()->val( 'actions' ); + $actions = Context::get()->getGlobalConfiguration()->val( 'actions' ); foreach ( $actions as $actionClassName ) { $action = new $actionClassName; diff --git a/Core/ProviderConfiguration.php b/Core/ProviderConfiguration.php new file mode 100644 index 0000000..ac066e6 --- /dev/null +++ b/Core/ProviderConfiguration.php @@ -0,0 +1,46 @@ +<?php + +namespace SmashPig\Core; + + +class ProviderConfiguration extends Configuration { + protected $provider; + + protected $defaultOptions; + + /** + * @param string $provider + * @param array $defaults + * @return static + */ + public static function createForProvider( $provider, $defaults = array() ) { + $config = new static(); + $config->provider = $provider; + $config->defaultOptions = $defaults; + + $config->loadDefaultConfig(); + return $config; + } + + /** + * @param array $defaults + * @return static + */ + public static function createDefault( $defaults ) { + $config = new static(); + $config->options = $defaults; + return $config; + } + + public function getDefaultSearchPath() { + if ( isset( $_SERVER['HOME'] ) ) { + $searchPath[] = "{$_SERVER['HOME']}/.smashpig/{$this->provider}/main.yaml"; + } + $searchPath[] = "/etc/smashpig/{$this->provider}/main.yaml"; + $searchPath[] = __DIR__ . "/../config/{$this->provider}/main.yaml"; + } + + public function getDefaultOptions() { + return $this->defaultOptions; + } +} \ No newline at end of file diff --git a/Core/QueueConsumers/BaseQueueConsumer.php b/Core/QueueConsumers/BaseQueueConsumer.php index d1f0f26..f620dcd 100644 --- a/Core/QueueConsumers/BaseQueueConsumer.php +++ b/Core/QueueConsumers/BaseQueueConsumer.php @@ -142,7 +142,7 @@ protected function handleError( $message, Exception $ex ) { if ( $ex instanceof RetryableException ) { $now = UtcDate::getUtcTimestamp(); - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); if ( !isset( $message['source_enqueued_time'] ) ) { $message['source_enqueued_time'] = UtcDate::getUtcTimestamp(); diff --git a/Maintenance/CreateIpnMessagesFromPendingDb.php b/Maintenance/CreateIpnMessagesFromPendingDb.php index 79b5f4a..678c4b3 100644 --- a/Maintenance/CreateIpnMessagesFromPendingDb.php +++ b/Maintenance/CreateIpnMessagesFromPendingDb.php @@ -104,7 +104,7 @@ } protected function getAstroPaySignature( $pendingMessage, $result ) { - $c = Context::get()->getConfiguration(); + $c = Context::get()->getGlobalConfiguration(); $login = $c->val( 'login' ); $secret = $c->val( 'secret' ); $signed = $login . $result . $pendingMessage['gross'] . $pendingMessage['order_id']; diff --git a/Maintenance/DumpConfig.php b/Maintenance/DumpConfig.php index e5664ab..f88659e 100644 --- a/Maintenance/DumpConfig.php +++ b/Maintenance/DumpConfig.php @@ -14,7 +14,7 @@ class DumpConfig extends MaintenanceBase { public function execute() { $context = Context::get(); - $config = $context->getConfiguration(); + $config = $context->getGlobalConfiguration(); $values = $config->val('/'); $yaml = Yaml::dump($values); diff --git a/Maintenance/MaintenanceBase.php b/Maintenance/MaintenanceBase.php index 8da0f7b..c197298 100755 --- a/Maintenance/MaintenanceBase.php +++ b/Maintenance/MaintenanceBase.php @@ -248,7 +248,7 @@ * @return mixed Value of the option or null if no default was provided */ protected function getOptionOrConfig( $name, $defaultNode ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); if ( $config->nodeExists( $defaultNode ) ) { $default = $config->val( $defaultNode ); } else { diff --git a/Maintenance/doMaintenance.php b/Maintenance/doMaintenance.php index d8507a4..eebe9d7 100644 --- a/Maintenance/doMaintenance.php +++ b/Maintenance/doMaintenance.php @@ -24,7 +24,7 @@ $maintenance->setup(); // Now that we have a config node, check for disablement - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); if ( $config->nodeExists( 'disabled' ) && $config->val( 'disabled' ) ) { print ( 'Processor disabled, will not execute.' ); exit( 1 ); diff --git a/PaymentProviders/Adyen/AdyenPaymentsAPI.php b/PaymentProviders/Adyen/AdyenPaymentsAPI.php index 73d4072..c7f8faa 100644 --- a/PaymentProviders/Adyen/AdyenPaymentsAPI.php +++ b/PaymentProviders/Adyen/AdyenPaymentsAPI.php @@ -17,7 +17,7 @@ $this->account = $account; - $c = Context::get()->getConfiguration(); + $c = Context::get()->getGlobalConfiguration(); $this->soapClient = new WSDL\Payment( $c->val( 'payment-provider/adyen/payments-wsdl' ), array( diff --git a/PaymentProviders/Adyen/Jobs/DownloadReportJob.php b/PaymentProviders/Adyen/Jobs/DownloadReportJob.php index 147e12d..b9064aa 100644 --- a/PaymentProviders/Adyen/Jobs/DownloadReportJob.php +++ b/PaymentProviders/Adyen/Jobs/DownloadReportJob.php @@ -37,7 +37,7 @@ public function execute() { $this->logger = new TaggedLogger( __CLASS__ ); - $c = Context::get()->getConfiguration(); + $c = Context::get()->getGlobalConfiguration(); // Construct the temporary file path $fileName = basename( $this->reportUrl ); diff --git a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php index a35bf16..314857d 100644 --- a/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php +++ b/PaymentProviders/Adyen/Jobs/ProcessCaptureRequestJob.php @@ -156,7 +156,7 @@ } protected function getRiskAction( $dbMessage ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $riskScore = isset( $dbMessage['risk_score'] ) ? $dbMessage['risk_score'] : 0; $this->logger->debug( "Base risk score from payments site is $riskScore, " . "raw CVV result is '{$this->cvvResult}' and raw AVS result is '{$this->avsResult}'." ); @@ -200,7 +200,7 @@ * @return \SmashPig\PaymentProviders\Adyen\AdyenPaymentsInterface */ protected function getApi() { - $api = Context::get()->getConfiguration()->object( 'payment-provider/adyen/api' ); + $api = Context::get()->getGlobalConfiguration()->object( 'payment-provider/adyen/api' ); $api->setAccount( $this->account ); return $api; } diff --git a/PaymentProviders/Amazon/Actions/CloseOrderReference.php b/PaymentProviders/Amazon/Actions/CloseOrderReference.php index 13bf1ad..1e31c59 100644 --- a/PaymentProviders/Amazon/Actions/CloseOrderReference.php +++ b/PaymentProviders/Amazon/Actions/CloseOrderReference.php @@ -15,7 +15,7 @@ return true; } - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $client = $config->object( 'payments-client', true ); $orderReferenceId = $msg->getOrderReferenceId(); diff --git a/PaymentProviders/Amazon/AmazonApi.php b/PaymentProviders/Amazon/AmazonApi.php index 6e27411..a14fbdd 100644 --- a/PaymentProviders/Amazon/AmazonApi.php +++ b/PaymentProviders/Amazon/AmazonApi.php @@ -21,7 +21,7 @@ protected static $instance; private function __construct() { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $this->client = $config->object( 'payments-client', true ); } @@ -38,7 +38,7 @@ * @return IpnHandlerInterface */ public static function createIpnHandler( $headers, $body ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $klass = $config->val( 'ipn-handler-class' ); return new $klass( $headers, $body ); } diff --git a/PaymentProviders/Amazon/Audit/AuditParser.php b/PaymentProviders/Amazon/Audit/AuditParser.php index c26e80d..0135520 100644 --- a/PaymentProviders/Amazon/Audit/AuditParser.php +++ b/PaymentProviders/Amazon/Audit/AuditParser.php @@ -8,7 +8,7 @@ class AuditParser { public function parseFile( $path ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $fileTypes = $config->val( 'audit/file-types' ); $data = array(); diff --git a/PaymentProviders/Amazon/Audit/ReportDownloader.php b/PaymentProviders/Amazon/Audit/ReportDownloader.php index d57d115..f70fd59 100644 --- a/PaymentProviders/Amazon/Audit/ReportDownloader.php +++ b/PaymentProviders/Amazon/Audit/ReportDownloader.php @@ -21,7 +21,7 @@ const FILE_REGEX = '/\d{4}-\d{2}-\d{2}-[_A-Z0-9]+_(?P<id>\d+).csv/'; public function __construct( $overrides ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $this->archivePath = empty( $overrides['archive-path'] ) ? $config->val( 'audit/archive-path' ) @@ -55,7 +55,7 @@ $this->ensureAndScanFolder( $this->downloadPath ); $this->reportsClient = - Context::get()->getConfiguration()->object( 'reports-client', true ); + Context::get()->getGlobalConfiguration()->object( 'reports-client', true ); Logger::info( 'Getting report list' ); $startDate = new DateTime( "-{$this->days} days", new DateTimeZone( 'UTC' ) ); diff --git a/PaymentProviders/Ingenico/Api.php b/PaymentProviders/Ingenico/Api.php index b4b1220..bad3f6d 100644 --- a/PaymentProviders/Ingenico/Api.php +++ b/PaymentProviders/Ingenico/Api.php @@ -29,7 +29,7 @@ $this->baseUrl = $baseUrl; $this->merchantId = $merchantId; // FIXME: provide objects in constructor - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $this->authenticator = $config->object( 'authenticator' ); } diff --git a/PaymentProviders/Ingenico/BankPaymentProvider.php b/PaymentProviders/Ingenico/BankPaymentProvider.php index 0f5b237..304a91c 100644 --- a/PaymentProviders/Ingenico/BankPaymentProvider.php +++ b/PaymentProviders/Ingenico/BankPaymentProvider.php @@ -28,7 +28,7 @@ parent::__construct( $options ); $this->cacheParameters = $options['cache-parameters']; // FIXME: provide objects in constructor - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $this->cache = $config->object( 'cache' ); } diff --git a/PaymentProviders/Ingenico/IdealStatusProvider.php b/PaymentProviders/Ingenico/IdealStatusProvider.php index 637207d..7d7b57e 100644 --- a/PaymentProviders/Ingenico/IdealStatusProvider.php +++ b/PaymentProviders/Ingenico/IdealStatusProvider.php @@ -31,7 +31,7 @@ $this->cacheParameters = $options['cache-parameters']; $this->availabilityUrl = $options['availability-url']; // FIXME: provide objects in constructor - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $this->cache = $config->object( 'cache' ); } diff --git a/PaymentProviders/Ingenico/IngenicoPaymentProvider.php b/PaymentProviders/Ingenico/IngenicoPaymentProvider.php index 9fe7ad2..8baf092 100644 --- a/PaymentProviders/Ingenico/IngenicoPaymentProvider.php +++ b/PaymentProviders/Ingenico/IngenicoPaymentProvider.php @@ -15,7 +15,7 @@ public function __construct( $options = array() ) { // FIXME: provide objects in constructor - $this->config = Context::get()->getConfiguration(); + $this->config = Context::get()->getGlobalConfiguration(); $this->api = $this->config->object( 'api' ); } } diff --git a/PaymentProviders/PayPal/Job.php b/PaymentProviders/PayPal/Job.php index 97552f6..5d81340 100644 --- a/PaymentProviders/PayPal/Job.php +++ b/PaymentProviders/PayPal/Job.php @@ -27,7 +27,7 @@ } public function execute() { - $this->config = Context::get()->getConfiguration(); + $this->config = Context::get()->getGlobalConfiguration(); if ( $this->is_reject() ) { // Returning false would cause it to go to the damaged queue, we diff --git a/PaymentProviders/PayPal/Listener.php b/PaymentProviders/PayPal/Listener.php index 2c7ac28..a7356d9 100644 --- a/PaymentProviders/PayPal/Listener.php +++ b/PaymentProviders/PayPal/Listener.php @@ -13,7 +13,7 @@ protected $config; public function execute( Request $request, Response $response ) { - $this->config = Context::get()->getConfiguration(); + $this->config = Context::get()->getGlobalConfiguration(); $requestValues = $request->getValues(); diff --git a/PaymentProviders/PayPal/Message.php b/PaymentProviders/PayPal/Message.php index 967beef..a56ceb9 100644 --- a/PaymentProviders/PayPal/Message.php +++ b/PaymentProviders/PayPal/Message.php @@ -7,7 +7,7 @@ */ abstract class Message { public static function fromIpnMessage( $ipnArray ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $message = array(); $map = $config->val( 'var_map' ); diff --git a/PaymentProviders/PayPal/PayPalPaymentsAPI.php b/PaymentProviders/PayPal/PayPalPaymentsAPI.php index 29efa21..7245fd2 100644 --- a/PaymentProviders/PayPal/PayPalPaymentsAPI.php +++ b/PaymentProviders/PayPal/PayPalPaymentsAPI.php @@ -24,7 +24,7 @@ $max_attempts = 7; for ( $i = 0; $i < $max_attempts; $i++ ) { - $url = Context::get()->getConfiguration()->val( 'postback-url' ); + $url = Context::get()->getGlobalConfiguration()->val( 'postback-url' ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); diff --git a/PaymentProviders/PaymentProviderFactory.php b/PaymentProviders/PaymentProviderFactory.php index f84f5f2..e273335 100644 --- a/PaymentProviders/PaymentProviderFactory.php +++ b/PaymentProviders/PaymentProviderFactory.php @@ -12,7 +12,7 @@ class PaymentProviderFactory { public static function getProviderForMethod( $paymentMethod ) { - $config = Context::get()->getConfiguration(); + $config = Context::get()->getGlobalConfiguration(); $node = "payment-provider/$paymentMethod"; return $config->object( $node ); } diff --git a/config/main.yaml b/config/main.yaml index 4036eb2..c6eefa1 100644 --- a/config/main.yaml +++ b/config/main.yaml @@ -79,47 +79,10 @@ <<: *REDIS queue: donations -logging: - root-context: SmashPig - # LOG_INFO - log-level: 6 - - enabled-log-streams: - - syslog - - log-streams: - syslog: - class: SmashPig\Core\Logging\LogStreams\SyslogLogStream - constructor-parameters: - # LOG_LOCAL0 - - 128 - # LOG_NDELAY - - 8 - -security: - ip-header-name: "" - ip-trusted-proxies: [] - ip-whitelist: [] - -endpoints: [] - -namespaces: [] - -include-files: [] - -include-paths: [] - -payment-provider: [] - -actions: [] - -email: - # TODO: Instead, format like: Name <email@domain> - from-address: - - sen...@contoso.com - - Example Sender - bounce-address: bounce+$1...@contoso.com - archive-addresses: [] +# Must implement Psr\Cache\CacheItemPoolInterface +# See PSR-6: http://www.php-fig.org/psr/psr-6/ +cache: + class: SmashPig\Core\Cache\HashCache maintenance: job-runner: @@ -135,16 +98,52 @@ requeue-max-age: 12000 -curl: - wrapper: - class: SmashPig\Core\Http\CurlWrapper - validator: - class: SmashPig\Core\Http\HttpStatusValidator - timeout: 7 - retries: 3 - user-agent: SmashPig +# The following settings can be overridden per provider in the files under +# each providers name in the config directory. Settings in this section should +# be obtained from the context's current ProviderConfiguration (which may be +# these defaults) rather than the GlobalConfiguration. +provider-defaults: + logging: + root-context: SmashPig + # LOG_INFO + log-level: 6 -# Must implement Psr\Cache\CacheItemPoolInterface -# See PSR-6: http://www.php-fig.org/psr/psr-6/ -cache: - class: SmashPig\Core\Cache\HashCache + enabled-log-streams: + - syslog + + log-streams: + syslog: + class: SmashPig\Core\Logging\LogStreams\SyslogLogStream + constructor-parameters: + # LOG_LOCAL0 + - 128 + # LOG_NDELAY + - 8 + + security: + ip-header-name: "" + ip-trusted-proxies: [] + ip-whitelist: [] + + endpoints: [] + + payment-provider: [] + + actions: [] + + email: + # TODO: Instead, format like: Name <email@domain> + from-address: + - sen...@contoso.com + - Example Sender + bounce-address: bounce+$1...@contoso.com + archive-addresses: [] + + curl: + wrapper: + class: SmashPig\Core\Http\CurlWrapper + validator: + class: SmashPig\Core\Http\HttpStatusValidator + timeout: 7 + retries: 3 + user-agent: SmashPig -- To view, visit https://gerrit.wikimedia.org/r/355577 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib5c810b0fd08e8c0147aaac1f75dda018f9723d2 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits