Reputation: 321
I am able to get list of all routes for controller as mentioned on https://stackoverflow.com/a/15950365/3900206 by @Qoop (Thanks to him for sharing).
And, it shows different routes as configured when run in dev and prod environment. But, I only want to list routes that appears in prod environment in dev environment also.
How can I list only those routes which are configured for prod environment from any environment (dev or prod or test)?
Is it possible as we can list environment specific routes from console as:
php app/console router:debug --env=prod
Update (Improving question):
I am looking for a way to list out routes of production environment from controller in any environment (dev, test or prod)
Upvotes: 1
Views: 3698
Reputation: 2263
I don't understand you have the command already, it can take --env option you can use it for dev/prod or test
php app/console router:debug --env=prod/test/dev
You can create your own AppKernel with the environment that you choose because there is no way that i am aware off that you can set the environment on the current kernel which doesnt make sens. instantiate a kernel prod for example and get the router service from its container. for more info on instantiating new environment http://symfony.com/fr/doc/current/cookbook/configuration/environments.html
$kernel = new \AppKernel('prod', true);
$kernel->boot();
/** @var $router \Symfony\Component\Routing\Router */
$router = $kernel->getContainer()->get('router');
$router->setOption('debug', true);
/** @var $collection \Symfony\Component\Routing\RouteCollection */
$collection = $router->getRouteCollection();
$allRoutes = $collection->all();
Upvotes: 4