Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all routes from an application using Zend Framework 2

How to easily list all routes that we have defined in our application with Zend Framework 2?

By "routes" I mean those which are defined in:

module/[moduleName]/config/module.config.php

under

'router' => array(
    'routes' => array(
        ...
    )
)

I need to list them all but I can't figure out how to do this easily and nor the documentation nor the forums helped me by now.

like image 858
Cyril F Avatar asked Aug 12 '13 21:08

Cyril F


1 Answers

You can find the complete (merged) config or dump the Router itself. There is no way to export all route objects, so there I've to disappoint you.

To get the complete config, get it from the service locator:

// $sl instanceof Zend\ServiceManager\ServiceManager

$config = $sl->get('COnfig');
$routes = $config['router']['routes'];

If you want to view all routes just for debugging purposes, you can use var_dump or similar on the router object:

// $sl instanceof Zend\ServiceManager\ServiceManager

$router = $sl->get('Router');
var_dump($router);

To get route instances you can build the routes yourself using the route plugin manager, but I am not sure that's the way you want to go...

like image 146
Jurian Sluiman Avatar answered Nov 11 '22 09:11

Jurian Sluiman