Home

Awesome

gimme Build Status

Inject your services with magic.

A super-simple library to auto-magically inject named services from a $services* argument. Services come from service providers, that can be introduced to Gimme through a simple stack layout.

* Or not, have a look at Gimme\Resolver::setArgumentName

<?php

use Gimme\Resolver;
use Pimple;
use Foo;

// Create a service provider, for this example, using Pimple:
$pimple = new Pimple;
$pimple['myService'] = function() {
    return new Foo;
};

// Introduce the provider to Gimme, wrapping it in a closure
// that knows how to talk to Pimple:
$resolver = new Resolver;
$resolver->pushProvider(
    function($serviceName) use($pimple) { return $pimple[$serviceName]; };
);

// Use it. Tell Gimme that this callable (which can be a closure, a function
// or a method) wants to use a service called 'myService', which one of the
// registered service providers will be able to fetch for you.
$resolver->call(function($services = array('myService')) {
    var_dump($services->myService); #=> instance of Foo
});

Features:

Should I use this?

Dunno. It was fun to work on, but I'm not going to be the one to tell you to use it. The code is solid, if there's a point in using it for your needs, it's a point for you to make.

Install it:

Use Composer, add the following to your composer.json:

{
    "require": {
        "filp/gimme": "dev-master"
    }
}

And then:

$ composer install