Exemplo n.º 1
0
 /**
  * @param $instance
  */
 public function initialize($instance, ServiceLocatorInterface $serviceLocator)
 {
     $instanceManager = $this->di->instanceManager;
     $this->di->instanceManager = $this->diInstanceManagerProxy;
     try {
         $this->di->injectDependencies($instance);
         $this->di->instanceManager = $instanceManager;
     } catch (\Exception $e) {
         $this->di->instanceManager = $instanceManager;
         throw $e;
     }
 }
 /**
  * Initialize an instance via zend-di.
  *
  * @param mixed|ContainerInterface $first Container when under
  *     zend-servicemanager v3, instance to initialize otherwise.
  * @param ContainerInterface|mixed $second Instance to initialize when
  *     under zend-servicemanager v3, container otherwise.
  * @return void
  */
 public function __invoke($first, $second)
 {
     if ($first instanceof AbstractPluginManager || $second instanceof ContainerInterface) {
         $instance = $first;
     } else {
         $instance = $second;
     }
     $instanceManager = $this->di->instanceManager;
     $this->di->instanceManager = $this->diInstanceManagerProxy;
     try {
         $this->di->injectDependencies($instance);
     } catch (Exception $e) {
         throw $e;
     } finally {
         $this->di->instanceManager = $instanceManager;
     }
 }
Exemplo n.º 3
0
 public function testDiWillInjectDependenciesForInstance()
 {
     $di = new Di();
     // for setter injection, the dependency is not required, thus it must be forced
     $classDef = new Definition\ClassDefinition('ZendTest\\Di\\TestAsset\\SetterInjection\\B');
     $classDef->addMethod('setA', true);
     $di->definitions()->addDefinition($classDef, false);
     // top of stack b/c Runtime is already there
     $b = new TestAsset\SetterInjection\B();
     $di->injectDependencies($b);
     $this->assertInstanceOf('ZendTest\\Di\\TestAsset\\SetterInjection\\A', $b->a);
 }