Skip to content

Commit

Permalink
#138 Implementation of container-interop v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Mar 16, 2014
1 parent 7ab8543 commit c60df75
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 32 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -22,6 +22,7 @@
"mnapoli/phpdocreader": "~1.2",
"myclabs/php-enum": "1.*",
"ocramius/proxy-manager": "~0.3",
"symfony/yaml": "2.*"
"symfony/yaml": "2.*",
"container-interop/container-interop": "~1.0"
}
}
7 changes: 4 additions & 3 deletions src/DI/Container.php
Expand Up @@ -20,6 +20,7 @@
use DI\Definition\Resolver\DefinitionResolver;
use DI\Definition\Resolver\ValueDefinitionResolver;
use Exception;
use Interop\Container\ContainerInterface as ContainerInteropInterface;
use InvalidArgumentException;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;

Expand All @@ -28,7 +29,7 @@
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class Container implements ContainerInterface, FactoryInterface
class Container implements ContainerInteropInterface, ContainerInterface, FactoryInterface
{
/**
* Map of entries with Singleton scope that are already resolved.
Expand Down Expand Up @@ -61,12 +62,12 @@ class Container implements ContainerInterface, FactoryInterface
*
* @param DefinitionManager $definitionManager
* @param LazyLoadingValueHolderFactory $proxyFactory
* @param ContainerInterface $wrapperContainer If the container is wrapped by another container.
* @param ContainerInteropInterface $wrapperContainer If the container is wrapped by another container.
*/
public function __construct(
DefinitionManager $definitionManager,
LazyLoadingValueHolderFactory $proxyFactory,
ContainerInterface $wrapperContainer = null
ContainerInteropInterface $wrapperContainer = null
) {
$this->definitionManager = $definitionManager;

Expand Down
1 change: 1 addition & 0 deletions src/DI/ContainerBuilder.php
Expand Up @@ -14,6 +14,7 @@
use DI\Definition\Source\PHPFileDefinitionSource;
use DI\Definition\Source\ReflectionDefinitionSource;
use Doctrine\Common\Cache\Cache;
use Interop\Container\ContainerInterface;
use InvalidArgumentException;
use ProxyManager\Configuration;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
Expand Down
23 changes: 5 additions & 18 deletions src/DI/ContainerInterface.php
Expand Up @@ -9,31 +9,18 @@

namespace DI;

use Interop\Container\ContainerInterface as BaseContainerInterface;

/**
* Describes the basic interface of a container.
*
* Focuses only on methods allowing to use the container, not configure it or configure entries.
*
* @since 4.0
* @deprecated Use Interop\Container\ContainerInterface instead, will be removed in 5.0.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
interface ContainerInterface
interface ContainerInterface extends BaseContainerInterface
{
/**
* Returns an entry of the container by its name.
*
* @param string $name Name of the entry to look for.
*
* @throws NotFoundException No entry was found for this name.
* @return mixed Entry. Can be anything: object, value, ...
*/
public function get($name);

/**
* Tests if the container can return an entry for the given name.
*
* @param string $name Name of the entry to look for.
* @return bool
*/
public function has($name);
}
2 changes: 1 addition & 1 deletion src/DI/Definition/Resolver/AliasDefinitionResolver.php
Expand Up @@ -9,9 +9,9 @@

namespace DI\Definition\Resolver;

use DI\ContainerInterface;
use DI\Definition\AliasDefinition;
use DI\Definition\Definition;
use Interop\Container\ContainerInterface;

/**
* Resolves an alias definition to a value.
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Definition/Resolver/ClassDefinitionResolver.php
Expand Up @@ -9,7 +9,6 @@

namespace DI\Definition\Resolver;

use DI\ContainerInterface;
use DI\Definition\ClassDefinition;
use DI\Definition\Definition;
use DI\Definition\EntryReference;
Expand All @@ -19,6 +18,7 @@
use DI\DependencyException;
use DI\NotFoundException;
use Exception;
use Interop\Container\ContainerInterface;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use ReflectionClass;
use ReflectionException;
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Definition/Resolver/FactoryDefinitionResolver.php
Expand Up @@ -9,9 +9,9 @@

namespace DI\Definition\Resolver;

use DI\ContainerInterface;
use DI\Definition\FactoryDefinition;
use DI\Definition\Definition;
use Interop\Container\ContainerInterface;

/**
* Resolves a factory definition to a value.
Expand Down
5 changes: 3 additions & 2 deletions src/DI/DependencyException.php
Expand Up @@ -9,10 +9,11 @@

namespace DI;

use Interop\Container\Exception\ContainerException;

/**
* Exception for the Container
*/
class DependencyException extends \Exception
class DependencyException extends \Exception implements ContainerException
{

}
5 changes: 3 additions & 2 deletions src/DI/NotFoundException.php
Expand Up @@ -9,10 +9,11 @@

namespace DI;

use Interop\Container\Exception\NotFoundException as BaseNotFoundException;

/**
* Exception thrown when a class or a value is not found in the container
*/
class NotFoundException extends \Exception
class NotFoundException extends \Exception implements BaseNotFoundException
{

}
4 changes: 2 additions & 2 deletions tests/UnitTests/DI/ContainerBuilderTest.php
Expand Up @@ -57,7 +57,7 @@ public function testContainerNotWrapped()

public function testContainerWrapped()
{
$otherContainer = $this->getMockForAbstractClass('DI\ContainerInterface');
$otherContainer = $this->getMockForAbstractClass('Interop\Container\ContainerInterface');

$builder = new ContainerBuilder('UnitTests\DI\Fixtures\FakeContainer');
$builder->wrapContainer($otherContainer);
Expand Down Expand Up @@ -94,7 +94,7 @@ public function testFluentInterface()
$result = $builder->setDefinitionCache($mockCache);
$this->assertSame($builder, $result);

$result = $builder->wrapContainer($this->getMockForAbstractClass('DI\ContainerInterface'));
$result = $builder->wrapContainer($this->getMockForAbstractClass('Interop\Container\ContainerInterface'));
$this->assertSame($builder, $result);
}
}
2 changes: 1 addition & 1 deletion tests/UnitTests/DI/Fixtures/FakeContainer.php
Expand Up @@ -9,8 +9,8 @@

namespace UnitTests\DI\Fixtures;

use DI\ContainerInterface;
use DI\Definition\DefinitionManager;
use Interop\Container\ContainerInterface;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;

/**
Expand Down

0 comments on commit c60df75

Please sign in to comment.