2017 © Pedro Peláez
 

library container

image

asgard/container

  • Saturday, August 19, 2017
  • by leyou
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3,138 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Container

Build Status, (*1)

The container provides services to the application. In the Asgard framework, the container is often stored in the container variable., (*2)

, (*3)

Installation

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.*

, (*5)

Usage in the Asgard Framework

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)

, (*7)

Usage outside the Asgard Framework

$container = new \Asgard\Container\Container;
#or
$container = new \Asgard\Container\Container::singleton();

, (*8)

Registering a service

$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)

, (*11)

Accessing a service

$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)

, (*13)

Creating a new service instance

$cache = $container->make('cache', [$param]);

, (*14)

Checking if a service exists

$container->has('cache');
#or
isset($container['cache']);

, (*15)

Removing a service

$container->remove('cache');
#or
unset($container['cache']);

, (*16)

ContainerAware Trait

This trait provides two methods:, (*17)

  • setContainer($container)
  • getContainer()

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;

, (*20)

Commands

ListCommand

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)

Contributing

Please submit all issues and pull requests to the asgardphp/asgard repository., (*25)

License

The Asgard framework is open-sourced software licensed under the MIT license, (*26)

The Versions

19/08 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php >=5.5.9
  • jeremeamia/superclosure ^2.0

 

The Development Requires

by Michel Hognerud

13/05 2016

v0.3.1

0.3.1.0

  Sources   Download

MIT

The Requires

  • php >=5.5.9
  • jeremeamia/superclosure ^2.0

 

by Michel Hognerud

12/05 2016

v0.3.0

0.3.0.0

  Sources   Download

MIT

The Requires

  • php >=5.5.9
  • jeremeamia/superclosure ^2.0

 

by Michel Hognerud

13/06 2015

v0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • jeremeamia/superclosure 2.*

 

by Michel Hognerud

09/09 2014

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • jeremeamia/superclosure 1.*

 

by Michel Hognerud