Skip to content

Commit

Permalink
[6.x] Adds support for Container::call($callableObject) (laravel#30156)
Browse files Browse the repository at this point in the history
* Adds support for Container::call()

* cs
  • Loading branch information
jarektkaczyk authored and i-bajrai committed Oct 4, 2019
1 parent cce3101 commit fb9cecd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Container/BoundMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ protected static function getCallReflector($callback)
{
if (is_string($callback) && strpos($callback, '::') !== false) {
$callback = explode('::', $callback);
} elseif (is_object($callback) && ! $callback instanceof Closure) {
$callback = [$callback, '__invoke'];
}

return is_array($callback)
Expand Down
17 changes: 17 additions & 0 deletions tests/Container/ContainerCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ public function testCallWithDependencies()
$this->assertInstanceOf(stdClass::class, $result[0]);
$this->assertSame('taylor', $result[1]);
}

public function testCallWithCallableObject()
{
$container = new Container;
$callable = new ContainerCallCallableStub;
$result = $container->call($callable);
$this->assertInstanceOf(ContainerCallConcreteStub::class, $result[0]);
$this->assertSame('jeffrey', $result[1]);
}
}

class ContainerTestCallStub
Expand Down Expand Up @@ -195,3 +204,11 @@ public static function inject(ContainerCallConcreteStub $stub, $default = 'taylo
return func_get_args();
}
}

class ContainerCallCallableStub
{
public function __invoke(ContainerCallConcreteStub $stub, $default = 'jeffrey')
{
return func_get_args();
}
}

0 comments on commit fb9cecd

Please sign in to comment.