Symfony 4 print all routes
So I put the pieces together:
Simplest way seems to be to inject Symfony\Component\Routing\RouterInterface
and then use it as a Router
. As I mentioned in the question, you can get the routes by using $router->getRouteCollection()->all()
where $router
is the injected dependency.
E.g.:
use Symfony\Component\Routing\RouterInterface;public function someMethodInController(Request $request, RouterInterface $router){ $routes = $router->getRouteCollection()->all(); // ...}
Use in any controller, this will return you an array of avaiable route objects.
$router = $this->get('router');$routes = $router->getRouteCollection()->all();