* @link http://pear.horde.org/index.php?package=Injector */ class Binder implements Horde_Injector_Binder { /** * Create an instance. * * @param Horde_Injector $injector The injector should provide all required * dependencies for creating the instance. * * @return mixed The concrete instance. */ public function create(Horde_Injector $injector) { return 'constructed'; } /** * Determine if one binder equals another binder * * @param Horde_Injector_Binder $binder The binder to compare against $this * * @return bool true if they are equal, or false if they are not equal */ public function equals(Horde_Injector_Binder $binder) { return false; } } $a = new Horde_Injector(new Horde_Injector_TopLevel()); $a->addBinder('constructed', new Binder()); var_dump($a->getInstance('constructed'));
public function testShouldAllowChildInjectorsAccessToParentInjectorBindings() { $mockInjector = $this->getMock('Horde_Injector_TopLevel', array('getBinder')); $mockInjector->expects($this->any())->method('getBinder')->with('BOUND_INTERFACE')->will($this->returnValue(new Horde_Injector_Binder_Mock())); $injector = new Horde_Injector($mockInjector); $binder = new Horde_Injector_Binder_Mock(); $injector->addBinder('BOUND_INTERFACE', $binder); $childInjector = $injector->createChildInjector(); $this->assertSame($binder, $childInjector->getBinder('BOUND_INTERFACE')); }