From a2ca7d825f426e3a07655dd0a05d7a9c746960c3 Mon Sep 17 00:00:00 2001 From: jdreesen Date: Sat, 12 Sep 2015 18:15:44 +0200 Subject: [PATCH] Let Invoker::call() determine if the factory definition is a valid callable This is needed to support the new 'Class::method' syntax that comes with php-di/invoker v1.1. --- .../Definition/Resolver/FactoryResolver.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/DI/Definition/Resolver/FactoryResolver.php b/src/DI/Definition/Resolver/FactoryResolver.php index 28c797b70..b77785e7c 100644 --- a/src/DI/Definition/Resolver/FactoryResolver.php +++ b/src/DI/Definition/Resolver/FactoryResolver.php @@ -13,6 +13,7 @@ use DI\Definition\FactoryDefinition; use DI\Definition\Definition; use Interop\Container\ContainerInterface; +use Invoker\Exception\NotCallableException; use Invoker\Invoker; use Invoker\ParameterResolver\NumericArrayResolver; @@ -56,20 +57,19 @@ public function __construct(ContainerInterface $container) */ 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]); + try { + return $this->invoker->call($definition->getCallable(), [$this->container]); + } catch (NotCallableException $e) { + throw new DefinitionException(sprintf( + 'The factory definition "%s" is not callable: %s', + $definition->getName(), + $e->getMessage() + )); + } } /**