public function dispatch(HttpRequest $request, HttpResponse $response)
    {
        if (false === $this->booted) {
            $this->boot();
        }


        // cache like a mother fucker
//        if(!$this->hasRouteInCache($request)) {
            $routeParams = $this->handleRouting($request);
//            $this->setRouteInCache($request, $routeParams);
            // @todo - move these 2 lines to setRouteInCache()
//            $routingCache = $this->serviceManager->get('RoutingCache');
//            $routingCache->set($request->getPathInfo(), $routeParams);
//        } else {
//            $routeParams = $this->getRouteFromCache($request);
//        }

        $request->attributes->add($routeParams);

        // Resolve our Controller
        $resolver = $this->serviceManager->get('ControllerResolver');
        if (false === $controller = $resolver->getController($request)) {
            throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s".', $request->getPathInfo()));
        }

        $controllerArguments = $resolver->getArguments($request, $controller);

        $result = call_user_func_array(
            $controller,
            $controllerArguments
        );

        if ($result === null) {
            throw new \Exception('Your action returned null. It must always return something');
        } elseif (is_string($result)) {
            $response->setContent($result);
        } elseif ($result instanceof SymfonyResponse || $response instanceof HttpResponse) {
            $response = $result;
        } else {
            throw new \Exception('Invalid response type returned from controller');
        }

        return $response;
    }
public function dispatch(HttpRequest $request, HttpResponse $response)
    {
        if (false === $this->booted) {
            $this->boot();
        }


        // cache like a mother fucker
//        if(!$this->hasRouteInCache($request)) {
            $routeParams = $this->handleRouting($request);
//            $this->setRouteInCache($request, $routeParams);
            // @todo - move these 2 lines to setRouteInCache()
//            $routingCache = $this->serviceManager->get('RoutingCache');
//            $routingCache->set($request->getPathInfo(), $routeParams);
//        } else {
//            $routeParams = $this->getRouteFromCache($request);
//        }

        $request->attributes->add($routeParams);

        // Resolve our Controller
        $resolver = $this->serviceManager->get('ControllerResolver');
        if (false === $controller = $resolver->getController($request)) {
            throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s".', $request->getPathInfo()));
        }

        $controllerArguments = $resolver->getArguments($request, $controller);

        $result = call_user_func_array(
            $controller,
            $controllerArguments
        );

        if ($result === null) {
            throw new \Exception('Your action returned null. It must always return something');
        } elseif (is_string($result)) {
            $response->setContent($result);
        } elseif ($result instanceof SymfonyResponse || $response instanceof HttpResponse) {
            $response = $result;
        } else {
            throw new \Exception('Invalid response type returned from controller');
        }

        return $response;
    }
public function dispatch ( HttpRequest $ request , HttpResponse $ response ) { if ( false === $ this -> booted ) { $ this -> boot ( ) ; } // cache like a mother fucker //        if(!$this->hasRouteInCache($request)) { $ routeParams = $ this -> handleRouting ( $ request ) ; //            $this->setRouteInCache($request, $routeParams); // @todo - move these 2 lines to setRouteInCache() //            $routingCache = $this->serviceManager->get('RoutingCache'); //            $routingCache->set($request->getPathInfo(), $routeParams); //        } else { //            $routeParams = $this->getRouteFromCache($request); //        } $ request -> attributes -> add ( $ routeParams ) ; // Resolve our Controller $ resolver = $ this -> serviceManager -> get ( 'ControllerResolver' ) ; if ( false === $ controller = $ resolver -> getController ( $ request ) ) { throw new NotFoundHttpException ( sprintf ( 'Unable to find the controller for path "%s".' , $ request -> getPathInfo ( ) ) ) ; } $ controllerArguments = $ resolver -> getArguments ( $ request , $ controller ) ; $ result = call_user_func_array ( $ controller , $ controllerArguments ) ; if ( $ result === null ) { throw new \ Exception ( 'Your action returned null. It must always return something' ) ; } elseif ( is_string ( $ result ) ) { $ response -> setContent ( $ result ) ; } elseif ( $ result instanceof SymfonyResponse || $ response instanceof HttpResponse ) { $ response = $ result ; } else { throw new \ Exception ( 'Invalid response type returned from controller' ) ; } return $ response ; }
Decide on a route to use and dispatch our module's controller action.

@param HttpRequest  $request
@param HttpResponse $response

@throws \Exception

@return HttpResponse
Decide on a route to use and dispatch our module s controller action .