Skip to content

Commit

Permalink
Added spec and fix for Router implicit binding through IoC (#16802)
Browse files Browse the repository at this point in the history
* Added spec and fix for IoC router implicit binding

* StyleCI fix
  • Loading branch information
asutoshpalai authored and taylorotwell committed Dec 15, 2016
1 parent 6e2f206 commit f880e09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ public function substituteImplicitBindings($route)
! $route->getParameter($parameter->name) instanceof Model) {
$method = $parameter->isDefaultValueAvailable() ? 'first' : 'firstOrFail';

$model = $class->newInstance();
$model = $this->container->make($class->name);

$route->setParameter(
$parameter->name, $model->where(
Expand Down
23 changes: 23 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,25 @@ public function testImplicitBindingsWithOptionalParameter()
$router->dispatch(Request::create('bar', 'GET'))->getContent();
}

public function testImplicitBindingThroughIOC()
{
$phpunit = $this;
$container = new Container;
$router = new Router(new Dispatcher, $container);
$container->singleton(Registrar::class, function () use ($router) {
return $router;
});

$container->bind('RoutingTestUserModel', 'RoutingTestExtendedUserModel');
$router->get('foo/{bar}', [
'middleware' => SubstituteBindings::class,
'uses' => function (RoutingTestUserModel $bar) use ($phpunit) {
$phpunit->assertInstanceOf(RoutingTestExtendedUserModel::class, $bar);
},
]);
$router->dispatch(Request::create('foo/baz', 'GET'))->getContent();
}

public function testDispatchingCallableActionClasses()
{
$router = $this->getRouter();
Expand Down Expand Up @@ -1390,6 +1409,10 @@ public function firstOrFail()
}
}

class RoutingTestExtendedUserModel extends RoutingTestUserModel
{
}

class ActionStub
{
public function __invoke()
Expand Down

0 comments on commit f880e09

Please sign in to comment.