-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #26 from Sam-Burns/remove-guzzle"
- Loading branch information
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/Adapter/GuzzleServiceBuilderContainerAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |