From b8026d9828d9614b7898e1c716040992b91c0e78 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Wed, 1 Jan 2014 20:17:19 -0800 Subject: [PATCH] Sending a response should not exit the program. We need to allow events to fire after the stop method is called. This will allow users to clean up resources, perform logging, etc. --- flight/net/Response.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/flight/net/Response.php b/flight/net/Response.php index 69a12fc..90f8ce5 100644 --- a/flight/net/Response.php +++ b/flight/net/Response.php @@ -164,13 +164,11 @@ class Response { } /** - * Sends the response and exits the program. + * Sends HTTP headers. + * + * @return object Self reference */ - public function send() { - if (ob_get_length() > 0) { - ob_end_clean(); - } - + public function sendHeaders() { if (!headers_sent()) { // Send status code header if (strpos(php_sapi_name(), 'cgi') !== false) { @@ -208,7 +206,24 @@ class Response { } } - exit($this->body); + return $this; + } + + /** + * Sends a HTTP response. + * + * @return object Self reference + */ + public function send() { + if (ob_get_length() > 0) { + ob_end_clean(); + } + + $this->sendHeaders(); + + echo $this->body; + + return $this; } }