Skip to content

Commit e720808

Browse files
[9.x] Adds Route::flush (#44386)
* Adds `Route::flush` * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent c958178 commit e720808

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
@@ -306,6 +306,16 @@ protected function parseControllerCallback()
306306
return Str::parseCallback($this->action['uses']);
307307
}
308308

309+
/**
310+
* Flush the cached container instance on the route.
311+
*
312+
* @return void
313+
*/
314+
public function flushController()
315+
{
316+
$this->controller = null;
317+
}
318+
309319
/**
310320
* Determine if the route matches a given request.
311321
*

tests/Routing/RoutingRouteTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,25 @@ public function testJsonResponseIsReturned()
18661866
$this->assertInstanceOf(JsonResponse::class, $response);
18671867
}
18681868

1869+
public function testRouteFlush()
1870+
{
1871+
$container = new Container;
1872+
$router = $this->getRouter();
1873+
1874+
$router->get('count', ActionCountStub::class);
1875+
$request = Request::create('count', 'GET');
1876+
1877+
$response = $router->dispatch($request);
1878+
$this->assertSame(1, (int) $response->getContent());
1879+
1880+
$response = $router->dispatch($request);
1881+
$this->assertSame(2, (int) $response->getContent());
1882+
1883+
$request->route()->flushController();
1884+
$response = $router->dispatch($request);
1885+
$this->assertSame(1, (int) $response->getContent());
1886+
}
1887+
18691888
public function testRouteRedirect()
18701889
{
18711890
$container = new Container;
@@ -2418,6 +2437,18 @@ public function __invoke()
24182437
}
24192438
}
24202439

2440+
class ActionCountStub
2441+
{
2442+
protected $count = 0;
2443+
2444+
public function __invoke()
2445+
{
2446+
$this->count++;
2447+
2448+
return $this->count;
2449+
}
2450+
}
2451+
24212452
interface ExampleMiddlewareContract
24222453
{
24232454
//

0 commit comments

Comments
 (0)