mnapoli/PHP-DI — pull request #49 by mnapoli (2013-03-24 15:15:24+00:00)
Title: Configuration refactoring

Configuration refactoring

- More annotations to allow full configuration through annotations
- Allow also full configuration through PHP config
- Allow also full configuration through YAML config?

Future usage:

```php
$configuration = $container->getConfiguration();
$configuration->useReflection(true);
$configuration->useAnnotations(true);
$configuration->addYAMLDefinitions('config/di.yml');
$configuration->addArrayDefinitions($arrayDefinitions);
$configuration->addArrayDefinitionsFromFile('config/di.php');
$configuration->setCache(new Doctrine\Common\Cache\ArrayCache(), $degug);
```

PHP array definition:

```php
$arrayDefinitions = [

'db.host' => 'localhost',
'db.port' => 5000,

'My\Interface' => [
// This is an alias
'class' => 'My\Implementation',
'lazy' => true,
'scope' => Scope::SINGLETON(),
],

'My\Implementation' => [
'constructor' => [
'host' => 'db.host',
'port' => 'db.port',
],
'methods' => [
'setFoo1' => My\Foo1::class, // PHP 5.5
'setFoo2' => [
'foo2' => 'My\Foo2',
],
'setFoo3' => [
'foo3' => [
'name' => 'My\Foo2',
'lazy' => true,
],
],
'setFoo4' => ['My\Foo2', 'My\Foo4bis'],
],
'properties' => [
'bar' => 'My\Bar',
'baz' => [
'name' => 'My\Baz',
'lazy' => true,
],
],
],

'myNamedInstance' => [
'function' => function(Container $c) {
return new MyClass($c['db.host']);
},
],

];
```

YAML definitions:

```yaml
db.host: localhost
db.port: 5000

My\Interface:
# This is an alias
class: My\Implementation
lazy: true
scope: singleton

My\Implementation:
constructor:
host: db.host
port: db.port
methods:
setFoo1: My\Foo1
setFoo2:
foo2: My\Foo2
setFoo3:
foo3:
name: My\Foo3
lazy: true
setFoo4: [My\Foo4, My\Foo4bis]
properties:
bar: My\Bar
baz:
name: My\Baz
lazy: true

myNamedInstance:
class: MyClass
```