orno/di — pull request #28 by chrisguitarguy (2014-10-18 03:23:10+00:00)
Title: Allow Auto-Resolution on Defined Services

There's a few big things here:

1. Reduce duplication between `ClosureDefinition` and `ClassDefinition` by pulling out common things in an `AbstractDefinition`.
2. Pull out parameter inspection (via reflection) into a trait so its resuable
3. Allow auto resolution of dependencies on defined services.

Take this something like this:

```php
use Psr\Log\LoggerInterface;
use Psr\Log\AbstractLogger;
use Orno\Di\Container;

class Logger extends AbstractLogger
{
public function log($level, $message, array $context=[])
{
// log stuff
}
}

interface Foo
{
public function doStuff();
}

class DefaultFoo implements Foo
{
public function __construct(LoggerInterface $logger)
{
// prolly do some stuff with $logger
}

public function doStuff()
{
// do stuff
}
}
```

Without putting `DefaultFoo` in the container everything for auto resolution works great!

```php
$container = new Container;
$container->add(LoggerInterface::class, Logger::class);

// works!
$foo = $container->get(DefaultFoo::class);
```

But if we alias `DefaultFoo` to `Foo` and don't add any arguments everything blows up.

```php
$container = new Container;
$container->add(LoggerInterface::class, Logger::class)
->withArgument('someapp');
$container->add(Foo::class, DefaultFoo::class);

// oops
$foo = $container->get(Foo::class);
```

The same sort of awesome auto resolution should be available to defined services on creation and that's what this PR does.

```php
$container = new Container;
$container->add(LoggerInterface::class, Logger::class)
->withArgument('someapp');
$container->add(Foo::class, DefaultFoo::class)
->autowire();

// works!
$foo = $container->get(DefaultFoo::class);
```