diff --git a/CHANGELOG.md b/CHANGELOG.md index f977c47..af6179b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Better error messages for auto-wire resolution issues #3 + ### Fixed -- ability to wrap aliased services #2 +- Ability to wrap aliased services #2 +- Bug in InteropWrapper which incorrectly would convert all exceptions into container exceptions. ## [0.2.1] - 2017-03-11 ### Added diff --git a/composer.json b/composer.json index 1924cb8..a2cad0a 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ } ], "require-dev": { - "container-interop/container-interop": "^1.1", - "krak/auto-args": "^0.2.0", + "krak/auto-args": "^0.3.1", "peridot-php/peridot": "^1.18", "pimple/pimple": "^3.0", "symfony/var-dumper": "^3.2" diff --git a/src/Box/AutoWireBox.php b/src/Box/AutoWireBox.php index 14a5222..bc8d3fc 100644 --- a/src/Box/AutoWireBox.php +++ b/src/Box/AutoWireBox.php @@ -3,22 +3,28 @@ namespace Krak\Cargo\Box; use Krak\Cargo; +use Krak\AutoArgs; +use Exception; class AutoWireBox implements Cargo\Box { private $class_name; private $auto_args; - public function __construct($auto_args, $class_name) { + public function __construct(AutoArgs\AutoArgs $auto_args, $class_name) { $this->auto_args = $auto_args; $this->class_name = $class_name; } public function unbox(Cargo\Container $c) { - return $this->auto_args->construct($this->class_name, [ - 'objects' => [$c], - 'container' => Cargo\toInterop($c), - ]); + try { + return $this->auto_args->construct($this->class_name, [ + 'objects' => [$c], + 'container' => Cargo\toInterop($c), + ]); + } catch (Exception $e) { + throw new Cargo\Exception\ContainerException("Could not automatically resolve service '$this->class_name'", 0, $e); + } } public function getType() { diff --git a/src/Container/Wrapper/InteropWrapper.php b/src/Container/Wrapper/InteropWrapper.php index 481921a..138a199 100644 --- a/src/Container/Wrapper/InteropWrapper.php +++ b/src/Container/Wrapper/InteropWrapper.php @@ -14,15 +14,7 @@ public function __construct(Cargo\Container $container) { } public function get($id) { - if (!$this->container->has($id)) { - throw new Container\Exception\NotFoundException("No entry was found for '$id'"); - } - - try { - return $this->container->get($id); - } catch (\Exception $e) { - throw new Container\Exception\ContainerException($e->getMessage()); - } + return $this->container->get($id); } public function has($id) {