Skip to content

Commit

Permalink
Merge pull request #12 from pulse00/feature/guzzle
Browse files Browse the repository at this point in the history
Added guzzle support
  • Loading branch information
henrikbjorn committed Mar 11, 2015
2 parents ac37f68 + 41072d6 commit 8675418
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
51 changes: 51 additions & 0 deletions DependencyInjection/Compiler/AdapterCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the HBStampieBundle package.
*
* (c) Henrik Bjornskov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace HB\StampieBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Class AdapterCompilerPass
* @package HB\StampieBundle\DependencyInjection\Compiler
*/
class AdapterCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$adapterMapping = array(
'buzz' =>'hb_stampie.adapter.buzz',
'guzzle.client' => 'hb_stampie.adapter.guzzle'
);

$this->addAdapterIfAvailable($container, $adapterMapping);
}


/**
* @param ContainerBuilder $container
* @param array $adapterMapping
*/
private function addAdapterIfAvailable(ContainerBuilder $container, array $adapterMapping)
{
foreach ($adapterMapping as $serviceId => $adapterId) {
if ($container->has($serviceId)) {
$container->getDefinition($adapterId)
->addArgument(new Reference($serviceId));
}
}
}
}
11 changes: 11 additions & 0 deletions HBStampieBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@
*/

namespace HB\StampieBundle;
use HB\StampieBundle\DependencyInjection\Compiler\AdapterCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author Henrik Bjornskov <[email protected]>
*/
class HBStampieBundle extends \Symfony\Component\HttpKernel\Bundle\Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new AdapterCompilerPass());
}
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ Add the configuration to `config.yml` as follows

``` yaml
hb_stampie:
adapter: buzz # buzz and noop are supported
adapter: buzz # buzz, guzzle and noop are supported
mailer: postmark # [send_grid, mail_chimp, postmark] is supported
server_token: POSTMARK_API_TEST # Replace with your ServerToken for you Service
```
For the `buzz` adapter to work it is required to have a `buzz` service fortunately [SensioBuzzBundle](http://github.com/sensio/SensioBuzzBundle)
provides this.

If you want to use the `guzzle` adapter, the [MisdGuzzleBundle](https://github.com/misd-service-development/guzzle-bundle) provides
the required dependencies.

## StampieExtra

This bundles allows you to use [StampieExtra](https://github.com/stof/StampieExtra) easily:
Expand Down
8 changes: 7 additions & 1 deletion Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@

<!-- Adapters -->
<parameter key="hb_stampie.adapter.buzz.class">Stampie\Adapter\Buzz</parameter>
<parameter key="hb_stampie.adapter.guzzle.class">Stampie\Adapter\Guzzle</parameter>
<parameter key="hb_stampie.adapter.noop.class">Stampie\Adapter\NoopAdapter</parameter>
</parameters>

<services>

<!-- Adapters -->
<service id="hb_stampie.adapter.buzz" class="%hb_stampie.adapter.buzz.class%">
<argument type="service" id="buzz" />
<argument><!-- Injected in AdapterCompilerPass --></argument>
</service>

<service id="hb_stampie.adapter.guzzle" class="%hb_stampie.adapter.guzzle.class%">
<argument><!-- Injected in AdapterCompilerPass --></argument>
</service>

<service id="hb_stampie.adapter.noop" class="%hb_stampie.adapter.noop.class%" />
Expand Down

0 comments on commit 8675418

Please sign in to comment.