Question: **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.

Answer: 
To get all routes I use [ZFTool](http://framework.zend.com/manual/current/en/modules/zendtool.introduction.html)

And console command to get dump of routes:

```
php vendor/bin/zf.php config list | grep routes

```

For Windows users (not tested):

```
php vendor/bin/zf.php config list |  findstr /R /C:"[routes]"

```
I needed to differentiate routes per module so that we can use BjyAuthorize's ACL setup respectively in different situations.

While there is more than one way to do to this such as shown by [Jurian Sluiman](https://stackoverflow.com/users/434223/jurian-sluiman) to read in all the routes (variables changed):

```php
<?php

// $this->services instanceof Zend\ServiceManager\ServiceManager

$config = $this->services->get('Config');
$routes = $config['router']['routes'];

```

You can obtain them as follows for future differentiation per module in a **function**:

```php
<?php

// $this->services instanceof Zend\ServiceManager\ServiceManager

/**
 * Load the Application's active modules.  
 * @note May need to specify additional modules that may not be 
 * loaded at this runtime.
 */
$moduleManager = $this->services->get('ModuleManager');
$moduleManager->loadModules();

// Retrieve array of module names.
$modules = $moduleManager->getModules();

// Setup a container for all active routes.
$routes = []; 

// Build array of all active routes.
foreach ($modules as $moduleName) {
    $module = $moduleManager->getModule($moduleName);
    $routes[$moduleName] = array_keys($module->getConfig()['router']['routes']);
}
// Whatever you care to do with them.
echo $routes;

```