diff --git a/composer.json b/composer.json index 4e2aa29df35d..b9d8137557dd 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "monolog/monolog": "~1.12", "mtdowling/cron-expression": "~1.0", "nesbot/carbon": "~1.20", + "psr/container": "~1.0", "ramsey/uuid": "~3.0", "swiftmailer/swiftmailer": "~6.0", "symfony/console": "~3.3", diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 8e33249153d4..2d275916c3c2 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -1222,4 +1222,24 @@ public function __set($key, $value) { $this[$key] = $value; } + + /** + * {@inheritdoc} + */ + public function get($id) + { + if ($this->has($id)) { + return $this->resolve($id); + } + + throw new EntryNotFoundException(); + } + + /** + * {@inheritdoc} + */ + public function has($id) + { + return $this->bound($id); + } } diff --git a/src/Illuminate/Container/EntryNotFoundException.php b/src/Illuminate/Container/EntryNotFoundException.php new file mode 100644 index 000000000000..bdcb6401d78c --- /dev/null +++ b/src/Illuminate/Container/EntryNotFoundException.php @@ -0,0 +1,10 @@ +bind('Illuminate\Tests\Container\IContainerContractStub', 'Illuminate\Tests\Container\ContainerImplementationStub'); $this->assertInstanceOf(ContainerDependentStub::class, $container->build(ContainerDependentStub::class)); } + + public function testContainerKnowsEntry() + { + $container = new Container; + $container->bind('Illuminate\Tests\Container\IContainerContractStub', 'Illuminate\Tests\Container\ContainerImplementationStub'); + $this->assertEquals(true, $container->has('Illuminate\Tests\Container\IContainerContractStub')); + } + + /** + * @expectedException \Illuminate\Container\EntryNotFoundException + */ + public function testUnknownEntryThrowsException() + { + $container = new Container; + $container->get('Taylor'); + } } class ContainerConcreteStub