stanlemon / simple-container
SimpleContainer is a simple service container with dependency injection.
Installs: 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/stanlemon/simple-container
Requires
- php: >=5.3.3
This package is auto-updated.
Last update: 2021-11-19 05:31:56 UTC
README
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();