Exemplo n.º 1
0
 /**
  * @param ReflectionFunction $reflectionFunction
  * @param Node[] $stmts
  * @return Node[]
  * @throws Exception\DomainException
  */
 private function translateParameters(ReflectionFunction $reflectionFunction, $stmts)
 {
     $map = array();
     $prepend = array();
     $reflectionParameters = $reflectionFunction->getParameters();
     foreach ($this->definition->getParams() as $position => $param) {
         $reflectionParameter = $reflectionParameters[$position];
         if ($param instanceof Param\ClassParam && $param->getClass() === Container::class) {
             $map[$reflectionParameter->getName()] = new Node\Expr\Variable('this');
         } else {
             if ($param instanceof Param\InjectionPointParam) {
                 $ip = new InjectionPoint();
                 $map[$reflectionParameter->getName()] = new InjectionPoint();
             } else {
                 $ip = new InjectionPoint();
                 $ip->class = $this->definition->getClass();
                 $prepend[] = new Node\Expr\Assign(new Node\Expr\Variable($reflectionParameter->getName()), $this->compileParam($param, $ip));
             }
         }
     }
     $visitor = new Visitor\VariableTranslatorVisitor($map);
     $fileTraverser = new NodeTraverser();
     $fileTraverser->addVisitor($visitor);
     $stmts = $fileTraverser->traverse($stmts);
     // Prepend
     return array_merge($prepend, $stmts);
 }
Exemplo n.º 2
0
 private function makeClosure(Definition\ClosureDefinition $definition, InjectionPoint $ip)
 {
     $ip->method = null;
     $params = array();
     foreach ($definition->getParams() as $position => $param) {
         $params[$position] = $this->makeParam($param);
     }
     $closure = $definition->getClosure();
     $reflectionFunction = new \ReflectionFunction($closure);
     return $reflectionFunction->invokeArgs($params);
 }