Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Allow non-method Callables #19168

Merged
merged 2 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Illuminate/Routing/RouteSignatureParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ protected static function fromClassMethodString($uses)
{
list($class, $method) = Str::parseCallback($uses);

if (! method_exists($class, $method) && is_callable($class, $method)) {
return [];
}

return (new ReflectionMethod($class, $method))->getParameters();
}
}
19 changes: 19 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,17 @@ public function testControllerRouting()
$this->assertFalse(isset($_SERVER['route.test.controller.except.middleware']));
}

public function testCallableControllerRouting()
{
$router = $this->getRouter();

$router->get('foo/bar', 'Illuminate\Tests\Routing\RouteTestControllerCallableStub@bar');
$router->get('foo/baz', 'Illuminate\Tests\Routing\RouteTestControllerCallableStub@baz');

$this->assertEquals('bar', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent());
$this->assertEquals('baz', $router->dispatch(Request::create('foo/baz', 'GET'))->getContent());
}

public function testControllerMiddlewareGroups()
{
unset(
Expand Down Expand Up @@ -1326,6 +1337,14 @@ public function index()
}
}

class RouteTestControllerCallableStub extends Controller
{
public function __call($method, $arguments = [])
{
return $method;
}
}

class RouteTestControllerMiddlewareGroupStub extends Controller
{
public function __construct()
Expand Down