jest/jest

A simple Dependency Injector for PHP 5.4+

Installs: 16

Dependents: 1

Stars: 1

Watchers: 1

Forks: 2

Language: PHP

v1.0.0 2014-01-30 01:56 UTC

README

A simple dependency injection library

Build Status

Jest looks to find the middle ground between the simplicity offered by tiny service locators like Pimple and the real dependency injection libraries like PHP-DI provide.

Jest uses an API very similar to Pimple and uses type casting and reflection to determine which dependencies need to be injected into the specified class or PHP callable (Closure, function, or method).

Usage:

$injector = new Jest\Injector();

// configure your shared dependencies

$injector['Request'] = function() {
    return new Request();
};

$injector['Session'] = function(Request $req) {
    return new Session($req);
};

// invoke a callable with the dependencies

$returnValue = $injector->invoke(function(Request $req, Session $sess) {
    return array($req, $sess);
});