This is my proposed version of how the routes.php should look like.
Why?
Depending on the application one has to build middlewares inside the routes.php
Some middlewares need the application instance like our own AuthenticationMiddleware
E.g. having only some routes which need authentication and not all routes.
But accessing $this inside a static function is not allowed. Passing on $this via
return static function (RouteBuilder $routes) use ($this)
is also not possible.
So one would have to build the objects outside of the static method and pass them through, which is kind of bad imho.
If we only added that static method so IDE's can have auto-completetion for the available RouteBuilder methods this is in my opinion the better solution.
The problem you described can be avoided by just removing the static keyword for the function, there's no need to remove the anonymous function all together.
This is my proposed version of how the routes.php should look like.
Why?
Depending on the application one has to build middlewares inside the routes.php Some middlewares need the application instance like our own AuthenticationMiddleware
E.g. having only some routes which need authentication and not all routes.
But accessing
$this
inside a static function is not allowed. Passing on$this
viais also not possible.
So one would have to build the objects outside of the static method and pass them through, which is kind of bad imho.
If we only added that static method so IDE's can have auto-completetion for the available RouteBuilder methods this is in my opinion the better solution.