예제 #1
0
 /**
  * @param Param $param
  * @param InjectionPoint $ip
  * @return Node\Expr
  * @throws Exception\DomainException
  */
 protected function compileParam(Param $param, InjectionPoint $ip)
 {
     if ($param instanceof Param\ClassParam) {
         $key = $param->getClass();
         // Just return this if it's asking for a container
         if ($key == Container::class) {
             return new Node\Expr\Variable('this');
         }
         // Get definition
         $definition = Utils::resolveAliasKey($this->definitions, $key, $param->isOptional());
         if ($definition) {
             return $this->compileParamInjectionPoint($definition, $ip);
         } else {
             return new Node\Expr\ConstFetch(new Node\Name('null'));
         }
     } else {
         if ($param instanceof Param\NamedParam) {
             $definition = Utils::resolveAliasKey($this->definitions, $param->getName(), true);
             if ($definition) {
                 return $this->compileParamInjectionPoint($definition, $ip);
             } else {
                 return new Node\Expr\MethodCall(new Node\Expr\Variable('this'), 'get', array(new Node\Arg(new Node\Scalar\String_($param->getName()))));
             }
         } else {
             if ($param instanceof Param\ValueParam) {
                 return new Node\Arg($this->compileValue($param->getValue()));
             } else {
                 if ($param instanceof Param\UnresolvedParam) {
                     $definition = Utils::resolveGlobalKey($this->definitions, $param->getName(), true);
                     if (!$definition) {
                         throw new Exception\OutOfBoundsException("Undefined identifier: " . $param->getName() . ' for definition: ' . $this->definition->getKey());
                     }
                     return $this->compileParamInjectionPoint($definition, $ip);
                 } else {
                     if ($param instanceof Param\InjectionPointParam) {
                         return new Node\Expr\ConstFetch(new Node\Name('WHOOPSIES'));
                     } else {
                         throw new Exception\DomainException('Unsupported parameter: ' . Utils::varInfo($param) . ' for definition: ' . $this->definition->getKey());
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 private function makeParam(Param $param)
 {
     if ($param instanceof Param\NamedParam) {
         return $this->get($param->getName());
     } else {
         if ($param instanceof Param\ClassParam) {
             if ($param->isOptional() && !$this->has($param->getClass())) {
                 return null;
             } else {
                 if (is_a($this, $param->getClass())) {
                     return $this;
                 } else {
                     return $this->get($param->getClass());
                 }
             }
         } else {
             if ($param instanceof Param\ValueParam) {
                 return $param->getValue();
             } else {
                 if ($param instanceof Param\UnresolvedParam) {
                     $definition = Utils::resolveGlobalKey($this->definitions, $param->getName());
                     return $this->get($definition->getKey());
                 } else {
                     if ($param instanceof Param\InjectionPointParam) {
                         if (count($this->stack) < 2) {
                             return new InjectionPoint();
                         } else {
                             return $this->stack[count($this->stack) - 2];
                         }
                     } else {
                         throw new Exception\DomainException("Unsupported param: " . Utils::varInfo($param));
                     }
                 }
             }
         }
     }
 }