Skip to content

Commit

Permalink
Merge pull request #14 from mindplay-dk/2.0.1
Browse files Browse the repository at this point in the history
2.0.1
  • Loading branch information
mindplay-dk authored Dec 7, 2017
2 parents 62f8b39 + 1e658b6 commit 0473972
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 57 deletions.
9 changes: 9 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Upgrading
=========

#### 2.0.1

This release improves *forward* compatibility with `psr/container`, and backwards compatibility with
the deprecated `container-interop/container-interop` package.

Version 3.0 will most likely remove backwards compatibility with `container-interop/container-interop`,
but as that is a breaking change, this update merely adds forward compatibility with the final PSR-11
package.

#### 2.0.0

Version 2 introduces some BC breaks from version 1.x, as described below.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"require": {
"php": ">=5.5",
"container-interop/container-interop": "~1.0"
"psr/container": "^1.0",
"container-interop/container-interop": "^1.2"
},
"require-dev": {
"mindplay/benchpress": "dev-master",
Expand Down
129 changes: 92 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace mindplay\unbox;

use Interop\Container\ContainerInterface;
use InvalidArgumentException;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use ReflectionClass;
use ReflectionFunction;
use ReflectionParameter;
Expand All @@ -27,10 +27,11 @@ public function __construct(Configuration $config)

$this->values = $this->values +
[
get_class($this) => $this,
__CLASS__ => $this,
ContainerInterface::class => $this,
FactoryInterface::class => $this,
get_class($this) => $this,
__CLASS__ => $this,
PsrContainerInterface::class => $this,
ContainerInterface::class => $this,
FactoryInterface::class => $this,
];
}

Expand All @@ -41,7 +42,6 @@ public function __construct(Configuration $config)
*
* @return mixed
*
* @throws ContainerException
* @throws NotFoundException
*/
public function get($name)
Expand All @@ -55,7 +55,7 @@ public function get($name)
$params = $this->resolve($reflection->getParameters(), $this->factory_map[$name]);

$this->values[$name] = call_user_func_array($factory, $params);
} elseif (!array_key_exists($name, $this->values)) {
} elseif (! array_key_exists($name, $this->values)) {
throw new NotFoundException($name);
}

Expand Down Expand Up @@ -129,16 +129,18 @@ public function call($callback, $map = [])
* @param mixed|mixed[] $map mixed list/map of parameter values (and/or boxed values)
*
* @return mixed
*
* @throws InvalidArgumentException
*/
public function create($class_name, $map = [])
{
if (!class_exists($class_name)) {
if (! class_exists($class_name)) {
throw new InvalidArgumentException("unable to create component: {$class_name}");
}

$reflection = new ReflectionClass($class_name);

if (!$reflection->isInstantiable()) {
if (! $reflection->isInstantiable()) {
throw new InvalidArgumentException("unable to create instance of abstract class: {$class_name}");
}

Expand All @@ -163,7 +165,6 @@ public function create($class_name, $map = [])
* @return array parameters
*
* @throws ContainerException
* @throws NotFoundException
*/
protected function resolve(array $params, $map, $safe = true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
*/
class ContainerException
extends Exception
implements InteropContainerException
implements InteropContainerException # which extends Psr\Container\ContainerExceptionInterface
{
}
Loading

0 comments on commit 0473972

Please sign in to comment.