Exemple #1
0
 /**
  * Dispatches a Request & Response
  *
  * @param \Cake\Network\Request $request The request to dispatch.
  * @param \Cake\Network\Response $response The response to dispatch.
  * @return \Cake\Network\Response a modified/replaced response.
  */
 public function dispatch(Request $request, Response $response)
 {
     if (Router::getRequest(true) !== $request) {
         Router::pushRequest($request);
     }
     $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
     $request = $beforeEvent->data['request'];
     if ($beforeEvent->result instanceof Response) {
         return $beforeEvent->result;
     }
     // Use the controller built by an beforeDispatch
     // event handler if there is one.
     if (isset($beforeEvent->data['controller'])) {
         $controller = $beforeEvent->data['controller'];
     } else {
         $controller = $this->factory->create($request, $response);
     }
     $response = $this->_invoke($controller);
     if (isset($request->params['return'])) {
         return $response;
     }
     $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
     return $afterEvent->data['response'];
 }
 /**
  * Gets controller to use, either plugin or application controller.
  *
  * @param \Cake\Network\Request $request Request object
  * @param \Cake\Network\Response $response Response for the controller.
  * @return \Cake\Controller\Controller
  */
 protected function _getController($request, $response)
 {
     $factory = new ControllerFactory();
     return $factory->create($request, $response);
 }