Example #1
0
 /**
  * Resolve a factory definition to a value.
  *
  * This will call the callable of the definition.
  *
  * @param FactoryDefinition $definition
  *
  * {@inheritdoc}
  */
 public function resolve(Definition $definition, array $parameters = [])
 {
     $callable = $definition->getCallable();
     if (!is_callable($callable)) {
         throw new DefinitionException(sprintf('The factory definition "%s" is not callable', $definition->getName()));
     }
     if (!$this->invoker) {
         $this->invoker = new Invoker(new NumericArrayResolver(), $this->container);
     }
     return $this->invoker->call($callable, [$this->container]);
 }
Example #2
0
 /**
  * Resolve a factory definition to a value.
  *
  * This will call the callable of the definition.
  *
  * @param FactoryDefinition $definition
  *
  * {@inheritdoc}
  */
 public function resolve(Definition $definition, array $parameters = [])
 {
     if (!$this->invoker) {
         $this->invoker = new Invoker(new NumericArrayResolver(), $this->container);
     }
     try {
         return $this->invoker->call($definition->getCallable(), [$this->container]);
     } catch (NotCallableException $e) {
         throw new DefinitionException(sprintf('Entry "%s" cannot be resolved: factory %s', $definition->getName(), $e->getMessage()));
     }
 }
Example #3
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);
 }
Example #4
0
 /**
  * Resolve a factory definition to a value.
  *
  * This will call the callable of the definition.
  *
  * @param FactoryDefinition $definition
  *
  * {@inheritdoc}
  */
 public function resolve(Definition $definition, array $parameters = [])
 {
     if (!$this->invoker) {
         $parameterResolver = new ResolverChain([new AssociativeArrayResolver(), new FactoryParameterResolver($this->container), new NumericArrayResolver()]);
         $this->invoker = new Invoker($parameterResolver, $this->container);
     }
     $callable = $definition->getCallable();
     try {
         $providedParams = [$this->container, $definition];
         $extraParams = $this->resolveExtraParams($definition->getParameters());
         $providedParams = array_merge($providedParams, $extraParams);
         return $this->invoker->call($callable, $providedParams);
     } catch (NotCallableException $e) {
         // Custom error message to help debugging
         if (is_string($callable) && class_exists($callable) && method_exists($callable, '__invoke')) {
             throw new DefinitionException(sprintf('Entry "%s" cannot be resolved: factory %s. Invokable classes cannot be automatically resolved if autowiring is disabled on the container, you need to enable autowiring or define the entry manually.', $definition->getName(), $e->getMessage()));
         }
         throw new DefinitionException(sprintf('Entry "%s" cannot be resolved: factory %s', $definition->getName(), $e->getMessage()));
     } catch (NotEnoughParametersException $e) {
         throw new DefinitionException(sprintf('Entry "%s" cannot be resolved: %s', $definition->getName(), $e->getMessage()));
     }
 }