orno/di — pull request #31 by hannesvdvreken (2014-12-12 15:04:54+00:00)
Title: Added a call method to the container that auto resolves its parameters

Added useful container method:

```php
\Orno\Di\Container::call(callable $callback, array $parameters = []);
```

Based on the `call` method of container in the upcoming Laravel 5.0 release.
But this version is significantly better because:

- Better type hinting of the actual method ([PHP 5.4's callable type hint](http://php.net/manual/en/language.types.callable.php)),
- Support for `Classname::staticMethod` as a parameter for `callable $callable`.

Added numerous tests for all kinds of situations like:

- Namespaced global methods,
- Static methods on namespaced classes
- Optional parameters

## Usage:

```php
namespace Vendor;

class Foo {
public static function foo() {}
public function baz() {}
}

function foo() {}

```

```php
use Vendor\Foo;

$c = new Container();
$result = $c->call(function ($bar, Foo $foo, $qux = null, array $baz = array()) {
// do something
return 'baz';
}, ['bar' => 'foobar']);

$c->call('\Vendor\foo');
$c->call('\Vendor\Foo::foo');

$foo = new Foo();
$c->call([$foo, 'baz']);
```

When something is not right, you will see it throw a `RuntimeException` with a meaningful message that says which parameter could not be resolved. You most probably didn't specify the named parameter in the optional parameter array, the parameter is not Type Hinted correctly, or it doesn't have an optional value.