Exemple #1
0
 /**
  * @param mixed $value
  * @return Node\Expr
  */
 public static function parserNodeFromValue($value)
 {
     if (is_array($value)) {
         $items = array();
         foreach ($value as $k => $v) {
             $items[] = new Node\Expr\ArrayItem(static::parserNodeFromValue($v), static::parserNodeFromValue($k));
         }
         return new Node\Expr\Array_($items);
     } else {
         if (is_string($value)) {
             return new Node\Scalar\String_($value);
         } else {
             if (is_int($value)) {
                 return new Node\Scalar\LNumber($value);
             } else {
                 if (is_float($value)) {
                     return new Node\Scalar\DNumber($value);
                 } else {
                     if (is_null($value)) {
                         return new Node\Expr\ConstFetch(new Node\Name('null'));
                     } else {
                         if (is_bool($value)) {
                             return new Node\Expr\ConstFetch(new Node\Name($value ? 'true' : 'false'));
                         } else {
                             throw new Exception\DomainException('Unsupported value: ' . Utils::varInfo($value));
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @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());
                     }
                 }
             }
         }
     }
 }
Exemple #3
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));
                     }
                 }
             }
         }
     }
 }
Exemple #4
0
 private function executeModules()
 {
     foreach ($this->modules as $module) {
         if (is_string($module)) {
             $module = new $module();
         }
         if (!$module instanceof Module) {
             throw new Exception\DomainException('Module must implement zdi\\Module, was: ' . Utils::varInfo($module));
         }
         $module->define($this);
     }
 }
Exemple #5
0
 /**
  * @param $param
  * @return Param
  * @throws Exception\DomainException
  */
 private function convertParam($param)
 {
     if (is_string($param)) {
         return new Param\NamedParam($param);
     } else {
         if ($param instanceof Param) {
             return $param;
         } else {
             throw new Exception\DomainException("Invalid parameter: " . Utils::varInfo($param));
         }
     }
 }