public function collect(Request $request, Response $response, \Exception $exception = null)
    {
        $collection = $this->container->get('routing');

        $_routes = $collection->all();

        $routes = array();

        foreach ($_routes as $routeName => $route) {
            $defaults = $route->getDefaults();
            $requirements = $route->getRequirements();

            $controller = isset($defaults['_controller']) ? $defaults['_controller'] : 'unknown';

            if (is_object($controller)) {
                $controller = get_class($controller);
            } elseif ($this->container->hasDefinition($controller)) {
                $controllerDefinition = $this->container->findDefinition($controller);
                /*  @var $controllerDefinition \Symfony\Component\DependencyInjection\Definition */
                $controller = '@'.$controller.' - '.$controllerDefinition->getClass();
            }

            $routes[$routeName] = array(
                'name' => $routeName,
                'pattern' => $route->getPattern(),
                'controller' => $controller,
                'method' => isset($requirements['_method']) ? $requirements['_method'] : 'ANY',
                'action' => isset($defaults['_action']) ? $defaults['_action'] : 'n/a',
            );
        }
        ksort($routes);
        $this->data['matchRoute'] = $request->attributes->get('_route');
        $this->data['routes'] = $routes;

        $this->data['resources'] = array();

        // get BB route sources
        foreach ($this->container->get('bbapp')->getConfig()->getDebugData() as $configFile => $configData) {
            if ('route.yml' == basename($configFile)) {
                $this->data['resources'][$configFile] = $configData;
            } elseif (array_key_exists('route', $configData)) {
                $this->data['resources'][$configFile] = $configData['route'];
            }
        }

        // get bundle route sources
        foreach ($this->container->get('bbapp')->getBundles() as $bundle) {
            foreach ($bundle->getConfig()->getDebugData() as $configFile => $configData) {
                if ('route.yml' == basename($configFile)) {
                    $this->data['resources'][$configFile] = $configData;
                } elseif (array_key_exists('route', $configData)) {
                    $this->data['resources'][$configFile] = $configData['route'];
                }
            }
        }
    }