From 2adf34430036a91950e024d0b5d6c80477bdaf15 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Mar 2021 08:53:56 -0600 Subject: [PATCH] Revert "[8.x] Respect custom route key with explicit route model binding (#36375)" This reverts commit 8c5292eb96d9cf104b9b3bcdd471bde59a117de1. --- src/Illuminate/Routing/RouteBinding.php | 8 +++---- src/Illuminate/Routing/Router.php | 2 +- tests/Routing/RoutingRouteTest.php | 31 ------------------------- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/Illuminate/Routing/RouteBinding.php b/src/Illuminate/Routing/RouteBinding.php index 45b2e8ec8d05..133a84a40b07 100644 --- a/src/Illuminate/Routing/RouteBinding.php +++ b/src/Illuminate/Routing/RouteBinding.php @@ -33,7 +33,7 @@ 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. @@ -41,7 +41,7 @@ protected static function createClassBinding($container, $binding) $callable = [$container->make($class), $method]; - return $callable($value, $route, $key); + return $callable($value, $route); }; } @@ -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; } @@ -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; } diff --git a/src/Illuminate/Routing/Router.php b/src/Illuminate/Routing/Router.php index 4e57ffc6ec9d..dfdb7ae7332e 100644 --- a/src/Illuminate/Routing/Router.php +++ b/src/Illuminate/Routing/Router.php @@ -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); } /** diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index f4244a3bbb3e..a0d4548dc06e 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -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; @@ -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);