Skip to content

Commit

Permalink
fix bound method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 20, 2020
1 parent 991d5c9 commit a7759d7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Illuminate/Container/BoundMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Container;

use Closure;
use Illuminate\Contracts\Container\BindingResolutionException;
use InvalidArgumentException;
use ReflectionFunction;
use ReflectionMethod;
Expand All @@ -23,12 +24,16 @@ class BoundMethod
*/
public static function call($container, $callback, array $parameters = [], $defaultMethod = null)
{
if (is_string($callback) && ! $defaultMethod && method_exists($callback, '__invoke')) {
$defaultMethod = '__invoke';
}

if (static::isCallableWithAtSign($callback) || $defaultMethod) {
return static::callClass($container, $callback, $parameters, $defaultMethod);
}

return static::callBoundMethod($container, $callback, function () use ($container, $callback, $parameters) {
return $callback(...static::getMethodDependencies($container, $callback, $parameters));
return $callback(...array_values(static::getMethodDependencies($container, $callback, $parameters)));
});
}

Expand Down Expand Up @@ -169,6 +174,10 @@ protected static function addDependencyForCallParameter($container, $parameter,
}
} elseif ($parameter->isDefaultValueAvailable()) {
$dependencies[] = $parameter->getDefaultValue();
} elseif (! $parameter->isOptional() && ! array_key_exists($paramName, $parameters)) {
$message = "Unable to resolve dependency [{$parameter}] in class {$parameter->getDeclaringClass()->getName()}";

throw new BindingResolutionException($message);
}
}

Expand Down

0 comments on commit a7759d7

Please sign in to comment.