library lazy-container
Smallest possible Dependency Injection container
m-r-r/lazy-container
Smallest possible Dependency Injection container
- Sunday, September 21, 2014
- by m-r-r
- Repository
- 1 Watchers
- 2 Stars
- 7 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 3 Versions
- 0 % Grown
Lazy Container
Usage
require __DIR__ . '/vendor/autoload.php';
use LazyContainer\Container;
class Foo
{
public $name;
function __construct($name)
{
echo "Instance of Foo created with name \"$name\".\n";
}
}
class Bar
{
public $foo;
function __construct(Container $c)
{
echo "Instance of Bar created.\n";
$this->foo = $c->foo;
}
}
class Baz
{
public $foo;
public $bar;
function __construct(Container $c)
{
echo "Instance of Baz created.\n";
$this->bar = $c->bar;
$this->foo = $c->foo;
}
}
$cont = new Container;
$cont->foo = function($self, $cfg) {
return new Foo($self->fooName);
};
$cont->bar = function($self) {
return new Bar($self);
};
$cont->baz = function($self) {
return new Baz($self);
};
$cont->fooName = 'Quux';
// Later:
var_dump($cont->baz instanceOf Baz
&& $cont->baz->bar === $cont->bar
&& $cont->baz->foo === $cont->bar->foo);
This program would print:, (*1)
Instance of Baz created.
Instance of Bar created.
Instance of Foo created with name "Quux".
bool(true)
dev-master
9999999-dev
Smallest possible Dependency Injection container
Sources
Download
BSD-3-Clause
The Requires
by
m-r-r
v0.1.0
0.1.0.0
Smallest possible Dependency Injection container
Sources
Download
BSD-3-Clause
The Requires
by
m-r-r
v0.1.0-alpha1
0.1.0.0-alpha1
Smallest possible Dependency Injection container
Sources
Download
BSD-3-Clause
The Requires
by
m-r-r