-
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.
- Loading branch information
1 parent
d212e45
commit cea98bf
Showing
4 changed files
with
76 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,51 @@ | ||
<?php | ||
|
||
namespace Acclimate\Container\Adapter; | ||
|
||
use Acclimate\Container\Exception\ContainerException as AcclimateContainerException; | ||
use Acclimate\Container\Exception\NotFoundException as AcclimateNotFoundException; | ||
use Interop\Container\ContainerInterface as AcclimateContainerInterface; | ||
use League\Container\ContainerInterface; | ||
use League\Container\Exception\ReflectionException; | ||
|
||
/** | ||
* An adapter from a League Container to the standardized ContainerInterface | ||
*/ | ||
class LeagueContainerAdapter implements AcclimateContainerInterface | ||
{ | ||
|
||
/** | ||
* @var ContainerInterface A League Container | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @param ContainerInterface $container A League Container | ||
*/ | ||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
public function get($id) | ||
{ | ||
try { | ||
return $this->container->get($id); | ||
} catch (\ReflectionException $prev) { | ||
throw AcclimateNotFoundException::fromPrevious($id, $prev); | ||
} catch (\Exception $prev) { | ||
throw AcclimateContainerException::fromPrevious($id, $prev); | ||
} | ||
} | ||
|
||
public function has($id) | ||
{ | ||
try { | ||
$this->container->get($id); | ||
} catch (ReflectionException $e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Acclimate\Container\Test\Adapter; | ||
|
||
use Acclimate\Container\Adapter\LeagueContainerAdapter; | ||
use League\Container\Container; | ||
use RuntimeException; | ||
|
||
/** | ||
* @covers \Acclimate\Container\Adapter\LeagueContainerAdapter | ||
*/ | ||
class LeagueContainerAdapterTest extends AbstractContainerAdapterTest | ||
{ | ||
protected function createContainer() | ||
{ | ||
$container = new Container(); | ||
|
||
$container->add('array_iterator', new \ArrayIterator(range(1, 5))); | ||
$container->add('error', new RuntimeException()); | ||
|
||
return new LeagueContainerAdapter($container); | ||
} | ||
} |