Description
- Laravel Version: 7.2.1
- PHP Version: 7.3.13
- Database Driver & Version: *
Description:
New route caching system, which uses CompiledRouteCollection
breaks usage of custom Route class. It breaks packages and solutions, which customize routing, like illuminatech/url-trailing-slash.
Steps To Reproduce:
-
declare custom
MyRouter
class extending standardIlluminate\Routing\Router
-
declare custom
MyRoute
class extending standardIlluminate\Routing\Route
with some custom logic. -
override
newRoute()
method for the router in the way it instantiates customMyRoute
instead of standard one -
define some routes
-
use
php artisan route:cache
to cache the routes
As the result all additional logic placed in MyRoute
is lost.
Code snippet
class MyRoute extends Illuminate\Routing\Route
{
public function run()
{
// custom run logic
// echo something for the test
echo __METHOD__; // works only if routes are not cached
return parent::run();
}
}
class MyRoute extends Illuminate\Routing\Router
{
protected function newRoute($methods, $uri, $action)
{
return (new MyRoute($methods, $uri, $action))
->setRouter($this)
->setContainer($this->container);
}
}
Relates to illuminatech/url-trailing-slash#4
Suggestion
CompiledRouteCollection::newRoute()
should invoke Router::newRoute()
inside of it, so any custom route creation logic is not lost.
This however requires to change visibility of the method from protected
to public
.