Skip to content

Commit

Permalink
Revert "Merge pull request #26 from Sam-Burns/remove-guzzle"
Browse files Browse the repository at this point in the history
This reverts commit ebac589, reversing
changes made to fbbe0f6.
  • Loading branch information
Sam-Burns committed Mar 1, 2016
1 parent d212e45 commit d18b115
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Command design pattern. You can also use the `FailoverOnMissContainer` decorator
## Supported Containers

* [Aura.Di Container](https://github.com/auraphp/Aura.Di/blob/develop/src/Aura/Di/ContainerInterface.php)
* [Guzzle Service Builder](https://github.com/guzzle/service/blob/master/Builder/ServiceBuilderInterface.php)
* [Laravel Container](https://github.com/laravel/framework/blob/master/src/Illuminate/Container/Container.php)
* [Nette DI Container](https://github.com/nette/nette/blob/master/Nette/DI/Container.php)
* [PHP-DI Container](https://github.com/mnapoli/PHP-DI/blob/master/src/DI/Container.php)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"php": ">=5.4.0",
"aura/di": "^1.0",
"illuminate/container": "^4.0 || ^5.0",
"guzzle/service": "^3.0"
"mnapoli/php-di": "^3.0",
"nette/nette": "^2.1",
"phpunit/phpunit": "^4.0 || ^5.0",
Expand Down
44 changes: 44 additions & 0 deletions src/Adapter/GuzzleContainerAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Acclimate\Container\Adapter;

use Acclimate\Container\Exception\ContainerException as AcclimateContainerException;
use Acclimate\Container\Exception\NotFoundException as AcclimateNotFoundException;
use Guzzle\Service\Builder\ServiceBuilderInterface as GuzzleContainerInterface;
use Guzzle\Service\Exception\ServiceNotFoundException as GuzzleNotFoundException;
use Interop\Container\ContainerInterface as AcclimateContainerInterface;

/**
* An adapter from a Guzzle ServiceBuilder to the standardized ContainerInterface
*/
class GuzzleContainerAdapter implements AcclimateContainerInterface
{
/**
* @var GuzzleContainerInterface A Guzzle ServiceBuilder
*/
private $container;

/**
* @param GuzzleContainerInterface $container A Guzzle ServiceBuilder
*/
public function __construct(GuzzleContainerInterface $container)
{
$this->container = $container;
}

public function get($id)
{
try {
return $this->container->get($id);
} catch (GuzzleNotFoundException $prev) {
throw AcclimateNotFoundException::fromPrevious($id, $prev);
} catch (\Exception $prev) {
throw AcclimateContainerException::fromPrevious($id, $prev);
}
}

public function has($id)
{
return isset($this->container[$id]);
}
}
1 change: 1 addition & 0 deletions src/Adapter/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'Zend\Di\LocatorInterface' => 'Acclimate\Container\Adapter\ZendDiContainerAdapter',
'Illuminate\Container\Container' => 'Acclimate\Container\Adapter\LaravelContainerAdapter',
'Aura\Di\ContainerInterface' => 'Acclimate\Container\Adapter\AuraContainerAdapter',
'Guzzle\Service\Builder\ServiceBuilderInterface' => 'Acclimate\Container\Adapter\GuzzleContainerAdapter',
'DI\Container' => 'Acclimate\Container\Adapter\PHPDIContainerAdapter',
'Nette\DI\Container' => 'Acclimate\Container\Adapter\NetteContainerAdapter',
'ArrayAccess' => 'Acclimate\Container\Adapter\ArrayAccessContainerAdapter',
Expand Down
28 changes: 28 additions & 0 deletions tests/Adapter/GuzzleServiceBuilderContainerAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Acclimate\Container\Test\Adapter;

use Guzzle\Service\Builder\ServiceBuilder;
use Acclimate\Container\Adapter\GuzzleContainerAdapter;

/**
* @covers \Acclimate\Container\Adapter\GuzzleContainerAdapter
*/
class GuzzleContainerAdapterTest extends AbstractContainerAdapterTest
{
protected function createContainer()
{
$container = new ServiceBuilder([
'array_iterator' => [
'class' => __NAMESPACE__ . '\Fixture\GuzzleValidService',
'params' => ['data' => range(1, 5)],
],
'error' => [
'class' => __NAMESPACE__ . '\Fixture\GuzzleBrokenService',
'params' => [],
]
]);

return new GuzzleContainerAdapter($container);
}
}

0 comments on commit d18b115

Please sign in to comment.