Example #1
0
 /**
  * Resolve a decorator definition to a value.
  *
  * This will call the callable of the definition and pass it the decorated entry.
  *
  * @param DecoratorDefinition $definition
  *
  * {@inheritdoc}
  */
 public function resolve(Definition $definition, array $parameters = [])
 {
     $callable = $definition->getCallable();
     if (!is_callable($callable)) {
         throw new DefinitionException(sprintf('The decorator "%s" is not callable', $definition->getName()));
     }
     $decoratedDefinition = $definition->getDecoratedDefinition();
     if (!$decoratedDefinition instanceof Definition) {
         if (!$definition->getSubDefinitionName()) {
             throw new DefinitionException('Decorators cannot be nested in another definition');
         }
         throw new DefinitionException(sprintf('Entry "%s" decorates nothing: no previous definition with the same name was found', $definition->getName()));
     }
     $decorated = $this->definitionResolver->resolve($decoratedDefinition);
     return call_user_func($callable, $decorated, $this->container);
 }