stanlemon/simple-container

This package is abandoned and no longer maintained. No replacement package was suggested.

SimpleContainer is a simple service container with dependency injection.

v0.1.1 2012-12-27 03:40 UTC

This package is auto-updated.

Last update: 2021-11-19 05:31:56 UTC


README

Build Status

SimpleContainer is a basic service container, it can store key => value objects and lazily load them using Closures. It also includes a newInstance() method which allows you to inject dependencies through constructors and setters providing for very basic dependency injection.

Example usages

Basic loading of services and retrieving of them

// Create the SimpleContainer
$container = new SimpleContainer();
// Set a service
$container->set('foo', function(){
	return new Foo();
});
// Get the service
$foo = $container->get('foo');
// Create a new class with services populaed
$bar = $container->newInstance('bar');
$bar->getFoo();