protected function matchRoute(Request $request, $type)
    {
        $router = $this->container->get('router');

        if ( ! $request->attributes->has('_controller')) {
            try {
                // Attempt to find the route from the request
                $matched = $router->match($request->getPathInfo());
            } catch (ResourceNotFoundException $e) {
                // If no route is found, throw handle a 404 exception
                throw new NotFoundHttpException(sprintf(
                    'No route found for path "%s".',
                    $request->getPath()
                ));
            }
        } else {
            // This will usually be the case if a kernel exception is thrown
            $matched = ['_controller' => $request->attributes->get('_controller')];
        }

        return $matched;
    }