Skip to content

Commit

Permalink
XOL-4975 Support for Symfony 3 (#11)
Browse files Browse the repository at this point in the history
* XOL-4975 Support for Symfony 3
* XOL-4975 update build matrix for travis
* Updated README
  • Loading branch information
anush authored Jan 22, 2020
1 parent f7c33eb commit e0859fd
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 494 deletions.
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.2
- 7.3
- 7.4

env:
- SYMFONY_VERSION="~2"
- SYMFONY_VERSION="~3"

before_script:
- composer self-update
- composer --version
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update
- composer install -n --dev --prefer-source

script: phpunit --coverage-text --configuration phpunit.xml.dist
7 changes: 4 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Xola\OmnipayBundle\DependencyInjection;

use Guzzle\Log\MessageFormatter;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
const DEBUG_FORMAT = '>>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{curl_stderr}';

/**
* Generates the configuration tree builder.
*
Expand All @@ -21,8 +22,8 @@ public function getConfigTreeBuilder()
->arrayNode('log')
->addDefaultsIfNotSet()
->children()
->scalarNode('format')
->defaultValue(MessageFormatter::DEBUG_FORMAT);
->scalarNode('format')
->defaultValue(Configuration::DEBUG_FORMAT);

return $treeBuilder;
}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Nelmio
Copyright (c) 2019 Xola, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Xola OmnipayBundle [![Build status...](https://secure.travis-ci.org/xola/Omnipay
This bundle integrates the [Omnipay payment processing library](https://github.com/adrianmacneil/omnipay) into
[Symfony2](http://symfony.com/).

This bundle supports Omnipay 2.x
This bundle supports Omnipay 3

Installation
------------
Expand All @@ -12,7 +12,7 @@ To install via [Composer](http://getcomposer.org/), add the following to your `c
```json
{
"require": {
"xola/omnipay-bundle": "1.*"
"xola/omnipay-bundle": "^3"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameters:

services:
omnipay:
class: %omnipay.service.class%
class: "%omnipay.service.class%"
arguments: [ "@service_container", "@logger" ]
tags:
- { name: monolog.logger, channel: omnipay }
28 changes: 13 additions & 15 deletions Service/Omnipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Xola\OmnipayBundle\Service;

use Guzzle\Http\Client;
use Guzzle\Log\MessageFormatter;
use Guzzle\Log\PsrLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
use Omnipay\Common\AbstractGateway;
use Http\Client\Common\Plugin\LoggerPlugin;
use Http\Client\Common\PluginClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Message\Formatter\FullHttpMessageFormatter;
use Omnipay\Common\GatewayFactory;
use Omnipay\Common\GatewayInterface;
use Omnipay\Common\Http\Client;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Component\DependencyInjection\Container;

class Omnipay
Expand Down Expand Up @@ -43,10 +44,10 @@ private function initConfig($parameters)
/**
* Returns an Omnipay gateway.
*
* @param string $key Gateway key as defined in the config
* @param string $key Gateway key as defined in the config
*
* @throws \RuntimeException If no gateway is configured for the key
* @return AbstractGateway
* @return GatewayInterface
* @throws RuntimeException If no gateway is configured for the key
*/
public function get($key = null)
{
Expand All @@ -65,17 +66,14 @@ public function get($key = null)
$gatewayName = $this->getGatewayName($key);
if (!$gatewayName) {
// Invalid gateway key
throw new \RuntimeException('Gateway key "' . $key . '" is not configured');
throw new RuntimeException('Gateway key "' . $key . '" is not configured');
}

$adapter = new PsrLogAdapter($this->logger);
$logPlugin = new LogPlugin($adapter, $this->config['log']['format']);

$client = new Client();
$client->addSubscriber($logPlugin);
$loggerPlugin = new LoggerPlugin($this->logger, new FullHttpMessageFormatter());
$httpClient = new PluginClient(HttpClientDiscovery::find(), [$loggerPlugin]);

$factory = new GatewayFactory();
/** @var GatewayInterface $gateway */
$client = new Client($httpClient);
$gateway = $factory->create($gatewayName, $client);

if (isset($config[$key])) {
Expand Down
Loading

0 comments on commit e0859fd

Please sign in to comment.