Skip to content

Commit

Permalink
Merge pull request #5 from krakphp/3-better-auto-wire-errors
Browse files Browse the repository at this point in the history
Better AutoWire Errors #3 

Closes #3
  • Loading branch information
ragboyjr authored Mar 28, 2017
2 parents 4b67ed5 + 640704e commit 2f91509
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 11 additions & 5 deletions src/Box/AutoWireBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 1 addition & 9 deletions src/Container/Wrapper/InteropWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2f91509

Please sign in to comment.