/**
 * Initializes the components and models a controller will be using.
 * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
 * Otherwise the return value of the controller action are returned.
 *
 * Works like {@see Dispatcher::_invoke()} but returns the full response instead the body only.
 *
 * Bancha needs to overwrite this method because we need the full response object not only the body of the response
 * object on return.
 *
 * @param Controller $controller Controller to invoke
 * @param CakeRequest $request The request object to invoke the controller for.
 * @param CakeResponse $response The response object to receive the output
 * @return CakeResponse te resulting response object
 */
 protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response)
 {
     $controller->constructClasses();
     $controller->startupProcess();
     $render = true;
     $result = $controller->invokeAction($request);
     if ($result instanceof CakeResponse) {
         $render = false;
         $response = $result;
     }
     if ($render && $controller->autoRender) {
         $response = $controller->render();
     } elseif ($response->body() === null) {
         $response->body($result);
     }
     $controller->shutdownProcess();
     if (isset($request->params['return'])) {
         return $response;
         // <-------------- only this line is changed, original: return $response->body();
     }
     $response->send();
 }
 /**
  * Initializes the components and models a controller will be using.
  * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
  * Otherwise the return value of the controller action are returned.
  *
  * @param Controller $controller Controller to invoke
  * @param CakeRequest $request The request object to invoke the controller for.
  * @param CakeResponse $response The response object to receive the output
  * @return CakeResponse the resulting response object
  */
 protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response)
 {
     $controller->constructClasses();
     $controller->startupProcess();
     $render = true;
     $result = $controller->invokeAction($request);
     if ($result instanceof CakeResponse) {
         $render = false;
         $response = $result;
     }
     if ($render && $controller->autoRender) {
         $response = $controller->render();
     } elseif (!$result instanceof CakeResponse && $response->body() === null) {
         $response->body($result);
     }
     $controller->shutdownProcess();
     return $response;
 }
Example #3
0
 /**
  * Initializes the components and models a controller will be using.
  * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
  * Otherwise the return value of the controller action are returned.
  *
  * @param Controller $controller Controller to invoke
  * @param CakeRequest $request The request object to invoke the controller for.
  * @return string Output as sent by controller
  * @throws MissingActionException when the action being called is missing.
  */
 protected function _invoke(Controller $controller, CakeRequest $request)
 {
     $controller->constructClasses();
     $controller->startupProcess();
     $methods = array_flip($controller->methods);
     if (!isset($methods[$request->params['action']])) {
         if ($controller->scaffold !== false) {
             App::import('Controller', 'Scaffold', false);
             return new Scaffold($controller, $request);
         }
         throw new MissingActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action']));
     }
     $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']);
     $response = $controller->getResponse();
     if ($controller->autoRender) {
         $controller->render();
     } elseif ($response->body() === null) {
         $response->body($result);
     }
     $controller->shutdownProcess();
     if (isset($request->params['return'])) {
         return $response->body();
     }
     $response->send();
 }
Example #4
0
 /**
  * Método que se encarga de invocar a la acción del controlador y
  * entregar la respuesta
  * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
  * @version 2014-03-22
  */
 private static function _invoke(Controller $controller, Network_Request $request, Network_Response $response)
 {
     // Iniciar el proceso
     $controller->startupProcess();
     // Ejecutar acción
     $result = $controller->invokeAction();
     // Renderizar proceso
     if ($controller->autoRender) {
         $response = $controller->render();
     } elseif ($response->body() === null) {
         $response->body($result);
     }
     // Detener el proceso
     $controller->shutdownProcess();
     // Retornar respuesta al cliente
     if (isset($request->params['return'])) {
         return $response->body();
     }
     // Enviar respuesta al cliente
     $response->send();
 }