Skip to content

Commit

Permalink
[5.4] Allow non-method Callables (#19168)
Browse files Browse the repository at this point in the history
* Allow non-method Callables

* Add callable controller test case
  • Loading branch information
ConnorVG authored and taylorotwell committed May 12, 2017
1 parent 13cfd83 commit 0cf1f76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 0cf1f76

Please sign in to comment.