2017 © Pedro Peláez
 

library container

Simple Dependency Injection Container.

image

mead-steve/container

Simple Dependency Injection Container.

  • Thursday, December 19, 2013
  • by MeadSteve
  • Repository
  • 0 Watchers
  • 0 Stars
  • 2 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Container

Very basic dependency injection container., (*1)

Build status

branch status
master Build Status

Example Usage

Setup a resource in the container:, (*2)

use \Meadsteve\Container\Container;
use \Meadsteve\Container\Singleton;

$MyContainer = new Container();

$MyContainer->DependancyOne = new Dependancy();
$MyContainer->MyObject = function(Container $Container) {
    return new MyObject($Container->DependancyOne);
};

Then when you need an instance of MyObject:, (*3)

$InstanceOfMyObject = $MyContainer->MyObject;

For some heavy objects you may not want to run the construction logic each time. Then you may want to use the singleton pattern. This is possible with the provided class:, (*4)

$MyContainer->DBUser = "DBGuy";
$MyContainer->Password = "SuperSecret10";
$MyContainer->DBBasedObject = new Singleton(function(Container $Container) {
    return new DBObject($Container->DBUser, $Container->Password);
});

Which is then retrieved in exactly the same way:, (*5)

$DBInstance = $MyContainer->DBBasedObject

The Versions

19/12 2013

dev-master

9999999-dev

Simple Dependency Injection Container.

  Sources   Download

MIT

The Requires

  • php >=5.3.0