Esempio n. 1
0
 /**
  * Create instance using a closure.
  *
  * If the closure depends on a Horde_Injector we want to limit its scope
  * so it cannot change anything that effects any higher-level scope.  A
  * closure should not have the responsibility of making a higher-level
  * scope change.
  * To enforce this we create a new child Horde_Injector.  When a
  * Horde_Injector is requested from a Horde_Injector it will return
  * itself. This means that the closure will only ever be able to work on
  * the child Horde_Injector we give it now.
  *
  * @param Horde_Injector $injector  Injector object.
  *
  * @return Horde_Injector
  */
 public function create(Horde_Injector $injector)
 {
     $childInjector = $injector->createChildInjector();
     $closure = $this->_closure;
     return $closure($childInjector);
 }
Esempio n. 2
0
 /**
  * Create instance using a factory method
  *
  * If the factory depends on a Horde_Injector we want to limit its scope
  * so it cannot change anything that effects any higher-level scope.  A
  * factory should not have the responsibility of making a higher-level
  * scope change.
  * To enforce this we create a new child Horde_Injector.  When a
  * Horde_Injector is requested from a Horde_Injector it will return
  * itself. This means that the factory will only ever be able to work on
  * the child Horde_Injector we give it now.
  *
  * @param Horde_Injector $injector  Injector object.
  *
  * @return Horde_Injector
  */
 public function create(Horde_Injector $injector)
 {
     $childInjector = $injector->createChildInjector();
     /* We use getInstance() here because we don't want to have to create
      * this factory more than one time to create more objects of this
      * type. */
     return $childInjector->getInstance($this->_factory)->{$this->_method}($childInjector);
 }
Esempio n. 3
0
 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'));
 }