mattjmattj/manioc

An IoC container based on Maybe and Pimple

1.0 2015-03-21 01:17 UTC

This package is auto-updated.

Last update: 2024-04-12 03:31:55 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

An IoC container based on Maybe and Pimple. Manioc actually directly depends on Pimple 3 and extends it with Maybe.

Installation

with composer

composer.phar require mattjmattj/manioc ~1.0

Basic usage

use Manioc\Container;
[...]

$container = new Container();

// A Manioc container is a Pimple 3 container
$container['feature.foo.enabled'] = false;

$container['Cache'] = function($c) {
	new Cache();
}

// ...but with Maybe! Here we use a feature switch to build an instance of Foo
// and wrap it with Maybe. If feature.foo is disabled, Maybe will provide a fake
// object
$container['Foo'] = $container->maybe('Foo',function($c) {
	if ($c['feature.foo.enabled']) {
		return new Foo();
	}
});

// we can also register factories:
$container['Foo'] = $container->maybeFactory('Foo',function($c) {
	if ($c['feature.foo.enabled']) {
		return new Foo();
	}
});

License

Manioc is licensed under BSD-2-Clause license.