Skip to content

Commit 91c49d9

Browse files
authored
Ports Route::flushController (#44393)
1 parent c1b765e commit 91c49d9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Illuminate/Routing/Route.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ protected function parseControllerCallback()
299299
return Str::parseCallback($this->action['uses']);
300300
}
301301

302+
/**
303+
* Flush the cached container instance on the route.
304+
*
305+
* @return void
306+
*/
307+
public function flushController()
308+
{
309+
$this->controller = null;
310+
}
311+
302312
/**
303313
* Determine if the route matches a given request.
304314
*

tests/Routing/RoutingRouteTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,25 @@ public function testResponseIsReturned()
17631763
$this->assertNotInstanceOf(JsonResponse::class, $response);
17641764
}
17651765

1766+
public function testRouteFlushController()
1767+
{
1768+
$container = new Container;
1769+
$router = $this->getRouter();
1770+
1771+
$router->get('count', ActionCountStub::class);
1772+
$request = Request::create('count', 'GET');
1773+
1774+
$response = $router->dispatch($request);
1775+
$this->assertSame(1, (int) $response->getContent());
1776+
1777+
$response = $router->dispatch($request);
1778+
$this->assertSame(2, (int) $response->getContent());
1779+
1780+
$request->route()->flushController();
1781+
$response = $router->dispatch($request);
1782+
$this->assertSame(1, (int) $response->getContent());
1783+
}
1784+
17661785
public function testJsonResponseIsReturned()
17671786
{
17681787
$router = $this->getRouter();
@@ -2304,6 +2323,18 @@ public function __invoke()
23042323
}
23052324
}
23062325

2326+
class ActionCountStub
2327+
{
2328+
protected $count = 0;
2329+
2330+
public function __invoke()
2331+
{
2332+
$this->count++;
2333+
2334+
return $this->count;
2335+
}
2336+
}
2337+
23072338
interface ExampleMiddlewareContract
23082339
{
23092340
//

0 commit comments

Comments
 (0)