A dependency injection container for PHP with annoation support. Pumice is heavly inspired by Google's Gucie for Java. If you have already worked with Guice, you'll feel familiar with Pumice's syntax.
This project is in early stage of its development, use it with care!
namespace foo;
class A {
public $value;
/**
* @DefaultValue("value")
*/
public function __construct($value = null) {
$this->value = $value;
}
}
namespace foo;
use foo\A;
class B {
public $a;
public function __construct(A $a) {
$this->a = $a;
}
}
class MyModule extends Module {
public function configure() {
$this->bind('some\X')->to('foo\B')->in(Scope::SINGLETON);
$this->bindAnnotation('DefaultValue')->toValue(1000);
}
}
$injector = Pumice::createInjector(new MyModule());
$b = $injector->getInstance('some\X');
$this->assertEquals(1000, $b->a->value);
For more examples look at the phpunit-tests.