Skip to content

Commit

Permalink
Revert "[8.x] Respect custom route key with explicit route model bind…
Browse files Browse the repository at this point in the history
…ing (#36375)"

This reverts commit 8c5292e.
  • Loading branch information
taylorotwell authored Mar 3, 2021
1 parent e3f48f7 commit 2adf344
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Routing/RouteBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public static function forCallback($container, $binder)
*/
protected static function createClassBinding($container, $binding)
{
return function ($value, $route, $key) use ($container, $binding) {
return function ($value, $route) use ($container, $binding) {
// If the binding has an @ sign, we will assume it's being used to delimit
// the class name from the bind method name. This allows for bindings
// to run multiple bind methods in a single class for convenience.
[$class, $method] = Str::parseCallback($binding, 'bind');

$callable = [$container->make($class), $method];

return $callable($value, $route, $key);
return $callable($value, $route);
};
}

Expand All @@ -57,7 +57,7 @@ protected static function createClassBinding($container, $binding)
*/
public static function forModel($container, $class, $callback = null)
{
return function ($value, $route, $key) use ($container, $class, $callback) {
return function ($value) use ($container, $class, $callback) {
if (is_null($value)) {
return;
}
Expand All @@ -67,7 +67,7 @@ public static function forModel($container, $class, $callback = null)
// throw a not found exception otherwise we will return the instance.
$instance = $container->make($class);

if ($model = $instance->resolveRouteBinding($value, $route->bindingFieldFor($key))) {
if ($model = $instance->resolveRouteBinding($value)) {
return $model;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public function substituteImplicitBindings($route)
*/
protected function performBinding($key, $value, $route)
{
return call_user_func($this->binders[$key], $value, $route, $key);
return call_user_func($this->binders[$key], $value, $route);
}

/**
Expand Down
31 changes: 0 additions & 31 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Str;
use LogicException;
use Mockery;
use PHPUnit\Framework\TestCase;
use stdClass;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
Expand Down Expand Up @@ -939,36 +938,6 @@ public function testModelBinding()
$this->assertSame('TAYLOR', $router->dispatch(Request::create('foo/taylor', 'GET'))->getContent());
}

public function testModelBindingWithCustomKey()
{
// Create the router.
$container = new Container();
$router = new Router(new Dispatcher(), $container);
$container->singleton(Registrar::class, function () use ($router) {
return $router;
});

$router->get('foo/{bar:custom}', ['middleware' => SubstituteBindings::class, 'uses' => function ($name) {
return $name;
}]);
$router->model('bar', RouteModelBindingStub::class);

// Mock the stub so we can verify that the method is called with custom key.
$mock = $container->instance(
RouteModelBindingStub::class,
Mockery::mock(RouteModelBindingStub::class),
);

$mock->shouldReceive('resolveRouteBinding')
->with('taylor', 'custom')
->once()
->andReturn('TAYLOR');

$this->assertSame('TAYLOR', $router->dispatch(Request::create('foo/taylor', 'GET'))->getContent());

Mockery::close();
}

public function testModelBindingWithNullReturn()
{
$this->expectException(ModelNotFoundException::class);
Expand Down

0 comments on commit 2adf344

Please sign in to comment.