get_class($client) ]); } // Set Request Options $client->options($options); return $client; } /** * 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 * * @throws Exception * @return Response */ public function execute_request(Request $request, Response $response) { //@codeCoverageIgnoreStart if (KO7::$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); } //@codeCoverageIgnoreEnd // 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=' . KO7::$charset); } $request->headers('content-length', (string)$request->content_length()); // If KO7 expose, set the user-agent if (KO7::$expose) { $request->headers('user-agent', KO7::version()); } try { $response = $this->_send_message($request, $response); } catch (Exception $e) { // Restore the previous request Request::$current = $previous; //@codeCoverageIgnoreStart if (isset($benchmark)) { // Delete the benchmark, it is invalid Profiler::delete($benchmark); } //@codeCoverageIgnoreEnd // Re-throw the exception throw $e; } // Restore the previous request Request::$current = $previous; //@codeCoverageIgnoreStart if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } //@codeCoverageIgnoreEnd // Return the response return $response; } /** * Set and get options for this request. * * @param mixed $key Option name, or array of options * @param mixed $value Option value * * @return mixed */ public function options($key = NULL, $value = NULL) { if ($key === NULL) { return $this->_options; } if (is_array($key)) { $this->_options = $key; } elseif ($value === NULL) { return Arr::get($this->_options, $key); } else { $this->_options[$key] = $value; } return $this; } }