Skip to content

Commit

Permalink
Ports Route::flushController (#44393)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Sep 30, 2022
1 parent c1b765e commit 91c49d9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ protected function parseControllerCallback()
return Str::parseCallback($this->action['uses']);
}

/**
* Flush the cached container instance on the route.
*
* @return void
*/
public function flushController()
{
$this->controller = null;
}

/**
* Determine if the route matches a given request.
*
Expand Down
31 changes: 31 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,25 @@ public function testResponseIsReturned()
$this->assertNotInstanceOf(JsonResponse::class, $response);
}

public function testRouteFlushController()
{
$container = new Container;
$router = $this->getRouter();

$router->get('count', ActionCountStub::class);
$request = Request::create('count', 'GET');

$response = $router->dispatch($request);
$this->assertSame(1, (int) $response->getContent());

$response = $router->dispatch($request);
$this->assertSame(2, (int) $response->getContent());

$request->route()->flushController();
$response = $router->dispatch($request);
$this->assertSame(1, (int) $response->getContent());
}

public function testJsonResponseIsReturned()
{
$router = $this->getRouter();
Expand Down Expand Up @@ -2304,6 +2323,18 @@ public function __invoke()
}
}

class ActionCountStub
{
protected $count = 0;

public function __invoke()
{
$this->count++;

return $this->count;
}
}

interface ExampleMiddlewareContract
{
//
Expand Down

0 comments on commit 91c49d9

Please sign in to comment.