/**
  * @inheritdoc
  */
 public function compile()
 {
     $definition = $this->definition;
     $identifier = $definition->getIdentifier();
     // Prepare method
     $method = $this->builderFactory->method($identifier)->makeProtected()->setDocComment('/**
                           * @return ' . $definition->getTypeHint() . '
                           */');
     // Prepare instance check
     $prop = null;
     if (!$definition->isFactory()) {
         $method->addStmt($this->makeSingletonCheck());
         $prop = new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $identifier);
     }
     // Prepare method body
     $providerDefinition = Utils::resolveAlias($this->definitions, Utils::resolveDefinition($this->definitions, $definition->getProvider()));
     $fetch = new Node\Expr\MethodCall(new Node\Expr\MethodCall(new Node\Expr\Variable('this'), $providerDefinition->getIdentifier()), 'get');
     if (!$definition->isFactory()) {
         $method->addStmt(new Node\Stmt\Return_(new Node\Expr\Assign(clone $prop, $fetch)));
     } else {
         $method->addStmt(new Node\Stmt\Return_($fetch));
     }
     return $method;
 }
Exemple #2
0
 /**
  * @param Definition[] $definitions
  * @param string $key
  * @param boolean $isOptional
  * @return null|Definition
  */
 public static function resolveAliasKey(array $definitions, $key, $isOptional = false)
 {
     $definition = Utils::resolveDefinition($definitions, $key, $isOptional);
     if ($definition) {
         $definition = Utils::resolveAlias($definitions, $definition, $isOptional);
     }
     return $definition;
 }