Esempio n. 1
0
 /**
  * Recursively looks for discovered dependencies
  *
  * @param string $name of the instances to get
  * @param array  $visited the array where discovered instance definitions will be stored
  */
 protected function doGetInjectedDefinitions($name, array &$visited)
 {
     if (isset($visited[$name])) {
         return;
     }
     try {
         $visited[$name] = $this->proxy->get($name);
     } catch (RuntimeException $e) {
         // usually abstract class or interface that cannot be resolved
         return;
     } catch (MissingPropertyException $e) {
         // usually missing parameters required for a particular instance
         return;
     }
     foreach ($visited[$name]->getParams() as $param) {
         if ($param instanceof GeneratorInstance) {
             /* @var $param GeneratorInstance */
             $this->doGetInjectedDefinitions($param->getName(), $visited);
         }
     }
     foreach ($visited[$name]->getMethods() as $method) {
         if (isset($method['params']) && is_array($method['params'])) {
             foreach ($method['params'] as $param) {
                 /* @var $param GeneratorInstance */
                 if ($param instanceof GeneratorInstance) {
                     /* @var $param GeneratorInstance */
                     $this->doGetInjectedDefinitions($param->getName(), $visited);
                 }
             }
         }
     }
 }
 public function testWillDiscoverInjectedMethodParameters()
 {
     $di = new Di();
     $a = new A();
     $di->instanceManager()->setParameters('ZendTest\\Di\\TestAsset\\SetterInjection\\B', array('a' => $a));
     $proxy = new DependencyInjectorProxy($di);
     $b = $proxy->get('ZendTest\\Di\\TestAsset\\SetterInjection\\B');
     $methods = $b->getMethods();
     $this->assertSame('setA', $methods[0]['method']);
     $this->assertSame($a, $methods[0]['params'][0]);
 }