diff --git a/src/UrlGenerator.php b/src/UrlGenerator.php index 4ded0b1..8d255f8 100644 --- a/src/UrlGenerator.php +++ b/src/UrlGenerator.php @@ -23,7 +23,7 @@ public function __construct($routes, Request $request, $assetRoot = null) if (!$routes instanceof RouteCollection && !(interface_exists('\Illuminate\Routing\RouteCollectionInterface') && is_subclass_of($routes, '\Illuminate\Routing\RouteCollectionInterface'))) { throw new \InvalidArgumentException('The $routes parameter has to be of type RouteCollection or RouteCollectionInterface for L6+.'); } - + parent::__construct($routes, $request, $assetRoot); } diff --git a/tests/Stubs/Controller.php b/tests/Stubs/Controller.php new file mode 100644 index 0000000..39f4dd7 --- /dev/null +++ b/tests/Stubs/Controller.php @@ -0,0 +1,11 @@ +get($tamperedUrl)->assertSee('Invalid Signature'); } + /** @test */ + public function it_allows_routes_to_be_cached() + { + $this->withoutExceptionHandling(); + $this->setSupportedLocales(['en']); + $this->setAppLocale('en'); + + Route::get('en/route', Controller::class.'@index'); + + $this->cacheRoutes(); + + $this->get('en/route')->assertSuccessful(); + } + + /** + * Cache registered routes. + * + * @return void + */ + protected function cacheRoutes() + { + $routes = Route::getRoutes(); + + foreach ($routes as $route) { + $route->prepareForSerialization(); + } + + $isLaravel7orGreater = method_exists($routes, 'compile'); + + if ($isLaravel7orGreater) { + $this->app['router']->setCompiledRoutes( + $routes->compile() + ); + + return; + } + + $this->app['router']->setRoutes($routes); + } + /** * Register a route. *