Example #1
0
 /**
  * Processes the request, executing the controller action that handles this
  * request, determined by the [Route].
  *
  * 1. Before the controller action is called, the [Controller::before] method
  * will be called.
  * 2. Next the controller action will be called.
  * 3. After the controller action is called, the [Controller::after] method
  * will be called.
  *
  * By default, the output from the controller is captured and returned, and
  * no headers are sent.
  *
  *     $request->execute();
  *
  * @param   Request   $request   A request object
  * @param   Response  $response  A response object
  * @return  Response
  * @throws  Kohana_Exception
  * @uses    [Kohana::$profiling]
  * @uses    [Profiler]
  */
 public function execute_request(Request $request, Response $response)
 {
     if (Kohana::$profiling) {
         // Set the benchmark name
         $benchmark = '"' . $request->uri() . '"';
         if ($request !== Request::$initial and Request::$current) {
             // Add the parent request uri
             $benchmark .= ' « "' . Request::$current->uri() . '"';
         }
         // Start benchmarking
         $benchmark = Profiler::start('Requests', $benchmark);
     }
     // Store the current active request and replace current with new request
     $previous = Request::$current;
     Request::$current = $request;
     // Resolve the POST fields
     if ($post = $request->post()) {
         $request->body(http_build_query($post, NULL, '&'))->headers('content-type', 'application/x-www-form-urlencoded; charset=' . Kohana::$charset);
     }
     $request->headers('content-length', (string) $request->content_length());
     // If Kohana expose, set the user-agent
     if (Kohana::$expose) {
         $request->headers('user-agent', Kohana::version());
     }
     try {
         $response = $this->_send_message($request, $response);
     } catch (Exception $e) {
         // Restore the previous request
         Request::$current = $previous;
         if (isset($benchmark)) {
             // Delete the benchmark, it is invalid
             Profiler::delete($benchmark);
         }
         // Re-throw the exception
         throw $e;
     }
     // Restore the previous request
     Request::$current = $previous;
     if (isset($benchmark)) {
         // Stop the benchmark
         Profiler::stop($benchmark);
     }
     // Return the response
     return $response;
 }