Skip to content

Instantly share code, notes, and snippets.

@hertsch
Last active April 26, 2017 08:28
Show Gist options
  • Save hertsch/5268848 to your computer and use it in GitHub Desktop.
Save hertsch/5268848 to your computer and use it in GitHub Desktop.
Silex: get a list of all routing URI patterns
// get all routing objects
$patterns = $app['routes']->getIterator(); // seems to be changed in Silex 1.1.0 !!! ... ->current()->all();
// walk through the routing objects
foreach ($patterns as $pattern) {
$match = $pattern->getPattern();
echo "$match<br />";
}
@masakielastic
Copy link

It is no need to use getIterato since $app['routes'] (RouteCollection) implements IteratorAggregate.

foreach ($app['routes'] as $pattern) {}

Fabien wrote article about IterateorAggregate.

@pablofmorales
Copy link

        $request = Request::createFromGlobals();
        $container->handle($request);

        foreach ($container['routes']->all() as $route) {          

        }

@gbirke
Copy link

gbirke commented Apr 26, 2017

If you want to list the routes before you have handled a request, you neeed to call $app->flush();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment