2017 © Pedro Peláez
 

library dicontainer

Simple DI container with auto-wiring.

image

wscore/dicontainer

Simple DI container with auto-wiring.

  • Saturday, November 9, 2013
  • by asaokamei
  • Repository
  • 1 Watchers
  • 1 Stars
  • 54 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

WScore.DiContainer

A simple Dependency Injection Container., (*1)

Usage

Creating an instance

Use instance scripts, (*2)

$container = include( 'WScore.DiContainer/scripts/instance.php' );

Setting and retrieving values.

Set and retrieve a value., (*3)

$container->set( 'some-id', 'a value' );
$value = $container->get( 'some-id' ); // gets a string: "a value".

Set a service object., (*4)

$container->set( 'service-this', '\name\space\className' );
$object = $container->get( 'service-this' ); // it's \name\space\className class.

Or, simply specify a class name to get an object., (*5)

$object = $container->get( '\name\space\className2' );

Getting another class

Set another class for a given class., (*6)

$container->set( '\some\class', '\name\space\className' );
$object = $container->get( '\some\class' ); // it's \name\space\className class.

Auto-Wiring/Discovery

Supports simple auto-wiring or auto-discovery of dependencies using annotations in phpdocs. The supported tags are: @Inject, @param, and @var., (*7)

The @Singleton annotation is also supported., (*8)

Sample PHP class code:, (*9)

/**
 * @Singleton
 */
class Sample {
    /**
     * @Inject
     * @var /class/class
     */
    private $property;

    /**
     * @Inject
     * @param /some/class1 $var
     * @param /some/class2 $var2
     */
    function __construct( $var, $var2 ) {}

    /**
     * @Inject
     * @param /some/class1 $var3
     */
    function setVar3( $var3 ) {}
}

Overwriting DI Option

The container can overwrite the dependency of any of the injection types: construct, setter, and property injections. Specify the option at get,, (*10)

$container->option( 'Some\Class' )
    ->setConstructor( 'var', 'another\class' )
    ->setSetter( 'setVar3', 'setter\class', )
    ->setProperty( 'property', 'property\class' );
$object = $container->get( 'Some\Class );

The Versions

09/11 2013

dev-master

9999999-dev

Simple DI container with auto-wiring.

  Sources   Download

by Asao Kamei

09/11 2013

dev-public

dev-public

Simple DI container with auto-wiring.

  Sources   Download

by Asao Kamei

31/08 2013

0.1.x-dev

0.1.9999999.9999999-dev

Simple DI container with auto-wiring.

  Sources   Download

by Asao Kamei

31/08 2013

0.1.0

0.1.0.0

Simple DI container with auto-wiring.

  Sources   Download

by Asao Kamei