aymane/roar

A very simple, lightweight, yet fully tested, container.

1.0 2016-08-08 14:29 UTC

This package is not auto-updated.

Last update: 2020-08-07 20:28:02 UTC


README

A very simple, lightweight, yet fully tested, container.

How to use it?

use Aymane\Roar\Container;

// Create a new instance of container
$container = new Container();

// Register your service using a simple closure
$container->add('foo', function() {
    return new Foo();
});

// Or share it (like a singleton!)
$container->share('bar', function() {
    return new Bar();
});

// Then use it!
$foo = $container->get('foo');
$bar = $container->get('bar');

Remember

When using the "add" method, you'll have multiple instances of your service when retrieving it using "get"

// registering service...
$foo1 = $container->get('foo');
$foo2 = $container->get('foo');

var_dump($foo1 === $foo2); // will return false

But, when you use "share", it's the opposite

// registering service...
$bar1 = $container->get('bar');
$bar2 = $container->get('bar');

var_dump($bar1 === $bar2); // will return true

License

The MIT License (MIT). Please see License File for more information.