1

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)

Community
  • 1
  • 1
San Thapa
  • 311
  • 7
  • 17

1 Answers1

4

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

Edit2 :

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();
Nawfal Serrar
  • 2,213
  • 1
  • 14
  • 22
  • I have updated my question and what I am looking for is a way to achieve the result of above command from controller class. – San Thapa Mar 19 '15 at 09:01
  • @SanThapa you can execute this command also by php with exec() unless you want more structured object? – Nawfal Serrar Mar 19 '15 at 09:19
  • Thanks but I am looking for another approach. If it possible from command then I think, it must be possible from script. – San Thapa Mar 19 '15 at 09:33
  • @SanThapa i have edited my answer, this one you should have all routes, give me feedback if this helps – Nawfal Serrar Mar 19 '15 at 09:44
  • I have achieved that already from the link mentioned on the question. It outputs all the routes of the running environment but what I meant is to get the routes of production environment only independent of the environment in which application is running. – San Thapa Mar 19 '15 at 10:14
  • @SanThapa something like this should do it (edited my answer) – Nawfal Serrar Mar 19 '15 at 10:54
  • Can this be achieved inside Controller/Action? The page loads and finally shows error `SQLSTATE[08004] [1040] Too many connections` – San Thapa Mar 19 '15 at 11:53
  • Thats another problem, try putting your max_connections in your mysql config file higher like : max_connections=250 or 500, it may also be something wrong with your code, btw are you working on some phpunit tests? PS: i edited my solution for more performant way. $kernel->boot(); – Nawfal Serrar Mar 20 '15 at 02:07
  • Thanks, the result is as expected, actually I am trying to list all routes of production environment. So, that I can create roles for every route and will be able to control access of routes on user basis. – San Thapa Mar 20 '15 at 04:28
  • Why not use the security.yml acl? – Nawfal Serrar Mar 20 '15 at 04:29
  • I am looking for a dynamic and interactive approach. So, I liked to configure this way. – San Thapa Mar 20 '15 at 05:05
  • If you like having tons of codes feel free but this is not the right way. anyway everyone have his own preferences ;) feel free – Nawfal Serrar Mar 20 '15 at 05:08