public function dispatch(ServerRequest $request, Response $response)
    {
        if (Router::getRequest(true) !== $request) {
            Router::pushRequest($request);
        }
        $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));

        $request = $beforeEvent->getData('request');
        if ($beforeEvent->getResult() instanceof Response) {
            return $beforeEvent->getResult();
        }

        // Use the controller built by an beforeDispatch
        // event handler if there is one.
        if ($beforeEvent->getData('controller') instanceof Controller) {
            $controller = $beforeEvent->getData('controller');
        } else {
            $controller = $this->factory->create($request, $response);
        }

        $response = $this->_invoke($controller);
        if ($request->getParam('return')) {
            return $response;
        }

        $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));

        return $afterEvent->getData('response');
    }
public function dispatch(ServerRequest $request, Response $response)
    {
        if (Router::getRequest(true) !== $request) {
            Router::pushRequest($request);
        }
        $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));

        $request = $beforeEvent->getData('request');
        if ($beforeEvent->getResult() instanceof Response) {
            return $beforeEvent->getResult();
        }

        // Use the controller built by an beforeDispatch
        // event handler if there is one.
        if ($beforeEvent->getData('controller') instanceof Controller) {
            $controller = $beforeEvent->getData('controller');
        } else {
            $controller = $this->factory->create($request, $response);
        }

        $response = $this->_invoke($controller);
        if ($request->getParam('return')) {
            return $response;
        }

        $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));

        return $afterEvent->getData('response');
    }
public function dispatch ( ServerRequest $ request , Response $ response ) { if ( Router :: getRequest ( true ) !== $ request ) { Router :: pushRequest ( $ request ) ; } $ beforeEvent = $ this -> dispatchEvent ( 'Dispatcher.beforeDispatch' , compact ( 'request' , 'response' ) ) ; $ request = $ beforeEvent -> getData ( 'request' ) ; if ( $ beforeEvent -> getResult ( ) instanceof Response ) { return $ beforeEvent -> getResult ( ) ; } // Use the controller built by an beforeDispatch // event handler if there is one. if ( $ beforeEvent -> getData ( 'controller' ) instanceof Controller ) { $ controller = $ beforeEvent -> getData ( 'controller' ) ; } else { $ controller = $ this -> factory -> create ( $ request , $ response ) ; } $ response = $ this -> _invoke ( $ controller ) ; if ( $ request -> getParam ( 'return' ) ) { return $ response ; } $ afterEvent = $ this -> dispatchEvent ( 'Dispatcher.afterDispatch' , compact ( 'request' , 'response' ) ) ; return $ afterEvent -> getData ( 'response' ) ; }
Dispatches a Request & Response

@param \Cake\Http\ServerRequest $request The request to dispatch.
@param \Cake\Http\Response $response The response to dispatch.
@return \Cake\Http\Response A modified/replaced response.
@throws \ReflectionException
Dispatches a Request & Response