Skip to content

Ulbrec87/ObjectBag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Dependency Injection Container 

You can use this library to initialize single instance of a class in your
application. 
You should always use Dependency Injection instead of Singleton (is considered
an antipattern).

Inspired by https://github.com/TomBZombie/Dice

Example:

class B {
  public function __construct() {

    } 
}

Class C {

  protected $b;

  public function __construct(B $b) {
    $this->b = $b;
  }

}

class D {

  protected $c;
  protected $t1;
  protected $t2;

  public function __construct(C $c, $type1, $type2) {
    $this->c = $c;
    $this->t1 = $type1;
    $this->t2 = $type2;
  }

}


$bag = new ObjectBag();
$d = $obj->getInstance('D',array("arg1","arg2"));
var_dump($d);

About

Simple Dependency Injection Container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages