Skip to content

Commit 3553668

Browse files
committed
Initial commit
0 parents  commit 3553668

File tree

14 files changed

+674
-0
lines changed

14 files changed

+674
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
composer.lock
3+
phpunit.xml

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- composer update --prefer-source
12+
13+
script: phpunit
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Swap Bundle.
5+
*
6+
* (c) Florian Voutzinos <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Florianv\SwapBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
/**
19+
* Adds providers tagged with "florianv_swap.provider" to the Swap service definition.
20+
*
21+
* @author Florian Voutzinos <[email protected]>
22+
*/
23+
class ProviderPass implements CompilerPassInterface
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function process(ContainerBuilder $container)
29+
{
30+
$definition = $container->getDefinition('florianv_swap.swap');
31+
32+
foreach ($container->findTaggedServiceIds('florianv_swap.provider') as $id => $attributes) {
33+
$definition->addMethodCall('addProvider', array(new Reference($id)));
34+
}
35+
}
36+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Swap Bundle.
5+
*
6+
* (c) Florian Voutzinos <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Florianv\SwapBundle\DependencyInjection;
13+
14+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
17+
/**
18+
* The configuration.
19+
*
20+
* @author Florian Voutzinos <[email protected]>
21+
*/
22+
class Configuration implements ConfigurationInterface
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getConfigTreeBuilder()
28+
{
29+
$treeBuilder = new TreeBuilder();
30+
$rootNode = $treeBuilder->root('florianv_swap');
31+
32+
$rootNode
33+
->children()
34+
->arrayNode('providers')
35+
->children()
36+
->scalarNode('yahoo_finance')->end()
37+
->scalarNode('google_finance')->end()
38+
->scalarNode('european_central_bank')->end()
39+
->arrayNode('open_exchange_rates')
40+
->children()
41+
->scalarNode('app_id')->isRequired()->cannotBeEmpty()->end()
42+
->booleanNode('enterprise')->defaultFalse()->end()
43+
->end()
44+
->end()
45+
->arrayNode('xignite')
46+
->children()
47+
->scalarNode('token')->isRequired()->cannotBeEmpty()->end()
48+
->end()
49+
->end()
50+
->end()
51+
->end()
52+
->end()
53+
->end()
54+
;
55+
56+
return $treeBuilder;
57+
}
58+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Swap Bundle.
5+
*
6+
* (c) Florian Voutzinos <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Florianv\SwapBundle\DependencyInjection;
13+
14+
use Symfony\Component\Config\FileLocator;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\Extension\Extension;
18+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19+
use Symfony\Component\DependencyInjection\Reference;
20+
21+
/**
22+
* The container extension.
23+
*
24+
* @author Florian Voutzinos <[email protected]>
25+
*/
26+
class FlorianvSwapExtension extends Extension
27+
{
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function load(array $config, ContainerBuilder $container)
32+
{
33+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
34+
$loader->load('services.xml');
35+
36+
$config = $this->processConfiguration(new Configuration(), $config);
37+
38+
if (isset($config['providers'])) {
39+
foreach ($config['providers'] as $providerName => $providerConfig) {
40+
switch ($providerName) {
41+
case 'yahoo_finance':
42+
case 'google_finance':
43+
case 'european_central_bank':
44+
$this->addProvider($container, $providerName, array(
45+
new Reference('florianv_swap.client')
46+
));
47+
break;
48+
49+
case 'open_exchange_rates':
50+
$this->addProvider($container, $providerName, array(
51+
new Reference('florianv_swap.client'),
52+
$providerConfig['app_id'],
53+
$providerConfig['enterprise']
54+
));
55+
break;
56+
57+
case 'xignite':
58+
$this->addProvider($container, $providerName, array(
59+
new Reference('florianv_swap.client'),
60+
$providerConfig['token'],
61+
));
62+
break;
63+
}
64+
}
65+
}
66+
}
67+
68+
/**
69+
* Creates the provider definition and add it to the container.
70+
*
71+
* @param ContainerBuilder $container
72+
* @param string $name
73+
* @param array $arguments
74+
*/
75+
private function addProvider(ContainerBuilder $container, $name, $arguments = array())
76+
{
77+
$definition = new Definition('%florianv_swap.provider.'.$name.'.class%', $arguments);
78+
$definition->setPublic(false);
79+
$definition->addTag('florianv_swap.provider');
80+
81+
$container->setDefinition(sprintf('florianv_swap.provider.%s', $name), $definition);
82+
}
83+
}

FlorianvSwapBundle.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Swap Bundle.
5+
*
6+
* (c) Florian Voutzinos <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Florianv\SwapBundle;
13+
14+
use Florianv\SwapBundle\DependencyInjection\Compiler\ProviderPass;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\HttpKernel\Bundle\Bundle;
17+
18+
/**
19+
* The bundle.
20+
*
21+
* @author Florian Voutzinos <[email protected]>
22+
*/
23+
class FlorianvSwapBundle extends Bundle
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function build(ContainerBuilder $container)
29+
{
30+
$container->addCompilerPass(new ProviderPass());
31+
}
32+
}

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# FlorianvSwapBundle
2+
3+
[![Build Status](https://travis-ci.org/florianv/FlorianvSwapBundle.svg?branch=master)](https://travis-ci.org/florianv/FlorianvSwapBundle)
4+
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/aae83a1e-c3e5-48c1-aedb-1f1c9a5decfe/mini.png)](https://insight.sensiolabs.com/projects/aae83a1e-c3e5-48c1-aedb-1f1c9a5decfe)
5+
[![Total Downloads](http://img.shields.io/packagist/dt/florianv/swap-bundle.svg)](https://packagist.org/packages/florianv/swap-bundle)
6+
[![License](http://img.shields.io/packagist/l/florianv/swap-bundle.svg)](https://packagist.org/packages/florianv/swap-bundle)
7+
8+
This Bundle integrates the [Swap](https://github.com/florianv/swap) library with Symfony2.
9+
10+
## Documentation
11+
12+
[Read the Documentation for master](https://github.com/florianv/FlorianvSwapBundle/blob/master/Resources/doc/index.md)
13+
14+
All the installation instructions are located in the documentation.
15+
16+
## License
17+
18+
This bundle is under the MIT license. See the complete license in the bundle:
19+
20+
```
21+
Resources/meta/LICENSE
22+
```

Resources/config/services.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="florianv_swap.swap.class">Swap\Swap</parameter>
9+
<parameter key="florianv_swap.client.class">Guzzle\Http\Client</parameter>
10+
<parameter key="florianv_swap.provider.yahoo_finance.class">Swap\Provider\YahooFinance</parameter>
11+
<parameter key="florianv_swap.provider.google_finance.class">Swap\Provider\GoogleFinance</parameter>
12+
<parameter key="florianv_swap.provider.european_central_bank.class">Swap\Provider\EuropeanCentralBank</parameter>
13+
<parameter key="florianv_swap.provider.open_exchange_rates.class">Swap\Provider\OpenExchangeRates</parameter>
14+
<parameter key="florianv_swap.provider.xignite.class">Swap\Provider\Xignite</parameter>
15+
</parameters>
16+
17+
<services>
18+
<service id="florianv_swap.swap" class="%florianv_swap.swap.class%"/>
19+
<service id="florianv_swap.client" class="%florianv_swap.client.class%" public="false"/>
20+
</services>
21+
22+
</container>

0 commit comments

Comments
 (0)