php injection de dépendance code example

Example 1: conteneur d'injection de dépendance php

// short example of what DIC does
class Foo
{
    public function __construct(Bar $bar)
    {
    }
}

$foo = $container->get('Foo');
// Which is equivalent to the following
$bar = new Bar;
$foo = new Foo($bar);

Example 2: conteneur d'injection de dépendance php

class Foo
{
    public function __construct(Bar $bar)
    {
    }
}

$foo = $container->get('Foo');
// qui est équivalent à ce qui suit
$bar = new Bar;
$foo = new Foo($bar);

Tags:

Php Example