dev-master
9999999-dev
MIT
The Requires
- php >=5.5.9
- jeremeamia/superclosure ^2.0
The Development Requires
by Michel Hognerud
The container provides services to the application. In the Asgard framework, the container is often stored in the container variable., (*2)
If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries., (*4)
composer require asgard/container 0.*
The container is often accessible as a method parameter or through a ContainerAware object. You can also use the singleton but it is not recommended., (*6)
$container = new \Asgard\Container\Container; #or $container = new \Asgard\Container\Container::singleton();
$container->register('cache', function($container, $param) { return new \Cache($param); }); #or $container['cache'] = new \Cache($param); #or $container->set('cache', new \Cache($param));
Register a service without persistency:, (*9)
$container->register('cache', function($container, $param) { return new \Cache($param); }, false);
$container['cache'] will create a new instance every time it is called., (*10)
$cache = $container->get('cache', [$param]); #or $cache = $container['cache'];
If you call it multiple times, the container will make sure the same instance is returned every time., (*12)
$cache = $container->make('cache', [$param]);
$container->has('cache'); #or isset($container['cache']);
$container->remove('cache'); #or unset($container['cache']);
This trait provides two methods:, (*17)
and a protected member variable "$container"., (*18)
To use it, add the following line in a class just after the opening bracket, (*19)
use \Asgard\Container\ContainerAware;
Show all the services loaded in the application., (*21)
Usage:, (*22)
php console services [--defined] [--registered]
--defined: to show where a service was defined, (*23)
--registered: to shown where a service was registered, (*24)
Please submit all issues and pull requests to the asgardphp/asgard repository., (*25)
The Asgard framework is open-sourced software licensed under the MIT license, (*26)
MIT