Skip to content

Commit

Permalink
Let Invoker::call() determine if the factory definition is a valid ca…
Browse files Browse the repository at this point in the history
…llable

This is needed to support the new 'Class::method' syntax that comes with
php-di/invoker v1.1.
  • Loading branch information
jdreesen committed Sep 12, 2015
1 parent 8904225 commit a2ca7d8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/DI/Definition/Resolver/FactoryResolver.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
));
}
}

/**
Expand Down

0 comments on commit a2ca7d8

Please sign in to comment.