nurse/di

Dependency injection library

Installs: 286

Dependents: 1

Watchers: 2

Forks: 1

Language: PHP

1.0.1 2015-07-22 12:59 UTC

README

Very simple Dependency Injection Container for PHP

Code information:

Build Status Coverage Status Code Climate Scrutinizer Code Quality

Package information:

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status

Installing

Installing via Composer

Append the lib to your requirements key in your composer.json.

{
    // composer.json
    // [..]
    require: {
        // append this line to your requirements
        "nurse/di": "dev-master"
    }
}

For PHP 5.3 support use version 0.9.2.

Alternative install

Issues/Features proposals

Here is the issue tracker.

Usage

Defining a dependency:

$container = new Nurse\Container;

// Defining a dependency

$container->set('connection', function ($container) {
    $params = $container->get('connection_params');
    return new Connection($params);
})
->set('connection_params', function () {
    return array(
        'schema'   => 'someschema',
        'username' => 'root',
        'password' => 's3cr3t',
    );
});

// Retrieving the dependency (lazy loading)
$connection = $container->get('connection');

// alternatively you can use the singleton instance of the container

Nurse\Di::set('connection', function ($container) {
    $params = $container->get('connection_params');
    return new Connection($params);
})
->set('connection_params', function () {
    return array(
        'schema'   => 'someschema',
        'username' => 'root',
        'password' => 's3cr3t',
    );
});

$connection = Nurse\Di::get('connection');

Contributing

Please refer to the contribuiting guide.

Lincense

MIT

Authors