Skip to content

Commit

Permalink
Merge pull request #8 from anushr/log_format
Browse files Browse the repository at this point in the history
Allow customization of log format
  • Loading branch information
anush authored May 7, 2018
2 parents de73b39 + 00fa9f1 commit 7643fcd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

before_script:
- composer install -n --dev --prefer-source
Expand Down
27 changes: 27 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

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
{
/**
* Generates the configuration tree builder.
*
* @return TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('omnipay');
$rootNode->children()
->arrayNode('log')->children()
->scalarNode('format')
->defaultValue(MessageFormatter::DEBUG_FORMAT);

return $treeBuilder;
}
}
10 changes: 7 additions & 3 deletions DependencyInjection/OmnipayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Xola\OmnipayBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
Expand All @@ -19,7 +19,11 @@ class OmnipayExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('omnipay.log.format', $config['log']['format']);

$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
4 changes: 3 additions & 1 deletion Service/Omnipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ class Omnipay
protected $config;
protected $cache = array();
protected $logger;
private $container;

public function __construct(Container $container, LoggerInterface $logger)
{
$this->container = $container;
$this->initConfig($container->getParameterBag()->all());
$this->logger = $logger;
}
Expand Down Expand Up @@ -67,7 +69,7 @@ public function get($key = null)
}

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

$client = new Client();
$client->addSubscriber($logPlugin);
Expand Down
5 changes: 5 additions & 0 deletions Tests/Service/OmnipayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Xola\OmnipayBundle\Tests\Service;

use Guzzle\Log\MessageFormatter;
use Omnipay\Stripe\Gateway as StripeGateway;
use Xola\OmnipayBundle\Service\Omnipay;

Expand All @@ -26,6 +27,7 @@ private function buildService($params = array())
*/
private function getServiceContainer($params)
{
$params['omnipay.log.format'] = MessageFormatter::DEBUG_FORMAT;
$parameterBag = $this->getMock('Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface');

$parameterBag
Expand Down Expand Up @@ -708,6 +710,9 @@ public function testGetConfig()
$service = $this->buildService(array('container' => $serviceContainer));

$expected = array(
'log' => array(
'format' => MessageFormatter::DEBUG_FORMAT
),
'world_pay' => array(
'installationId' => 'abc123',
'secretWord' => 'xyz987',
Expand Down

0 comments on commit 7643fcd

Please sign in to comment.