Skip to content

Commit

Permalink
[5.7] [Option 1] Improve PSR-11 implementation (#25870)
Browse files Browse the repository at this point in the history
* Improve PSR-11 implementation

* Implementation more complex with better feedback

* Include one more test case
  • Loading branch information
deleugpn authored and taylorotwell committed Oct 4, 2018
1 parent 405aca4 commit 35b8219
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Container;

use Closure;
use Exception;
use ArrayAccess;
use LogicException;
use ReflectionClass;
Expand Down Expand Up @@ -613,11 +614,15 @@ public function make($abstract, array $parameters = [])
*/
public function get($id)
{
if ($this->has($id)) {
try {
return $this->resolve($id);
}
} catch (Exception $e) {
if ($this->has($id)) {
throw $e;
}

throw new EntryNotFoundException;
throw new EntryNotFoundException;
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,25 @@ public function testUnknownEntryThrowsException()
$container = new Container;
$container->get('Taylor');
}

/**
* @expectedException \Psr\Container\ContainerExceptionInterface
*/
public function testBoundEntriesThrowsContainerExceptionWhenNotResolvable()
{
$container = new Container;
$container->bind('Taylor', IContainerContractStub::class);

$container->get('Taylor');
}

public function testContainerCanResolveClasses()
{
$container = new Container;
$class = $container->get(ContainerConcreteStub::class);

$this->assertInstanceOf(ContainerConcreteStub::class, $class);
}
}

class ContainerConcreteStub
Expand Down

0 comments on commit 35b8219

Please sign in to comment.