From: Alexandre Emsenhuber Date: Tue, 5 Jul 2011 15:05:14 +0000 (+0000) Subject: * Don't create a WebRequest obhject in CLI mode but a FauxRequest; avoids some useles... X-Git-Tag: 1.31.0-rc.0~29062 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=2f7f99b1f1931107eed64b292eb8a20eb2bf394a;p=lhc%2Fweb%2Fwiklou.git * Don't create a WebRequest obhject in CLI mode but a FauxRequest; avoids some useless notices about headers already sent (I know this is more a PHP silliness, but anyway) * Added HTTP response code parsing (sending a "HTTP/1.x code" header was throwing a NOTICE about undefined index on the result of the explode() call) and storage; added FauxResponse::getStatusCode() to retrieve it --- diff --git a/includes/Setup.php b/includes/Setup.php index 4f975f16cf..82bf4424ca 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -364,14 +364,16 @@ if( is_null( $wgLocalTZoffset ) ) { $wgLocalTZoffset = date( 'Z' ) / 60; } -# Can't stub this one, it sets up $_GET and $_REQUEST in its constructor -$wgRequest = new WebRequest; - # Useful debug output global $wgCommandLineMode; if ( $wgCommandLineMode ) { + $wgRequest = new FauxRequest( array() ); + wfDebug( "\n\nStart command line script $self\n" ); } else { + # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor + $wgRequest = new WebRequest; + $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}"; if ( $wgDebugPrintHttpHeaders ) { diff --git a/includes/WebResponse.php b/includes/WebResponse.php index 624104169a..a2d257c13a 100644 --- a/includes/WebResponse.php +++ b/includes/WebResponse.php @@ -77,6 +77,7 @@ class WebResponse { class FauxResponse extends WebResponse { private $headers; private $cookies; + private $code; /** * Stores a HTTP header @@ -85,10 +86,19 @@ class FauxResponse extends WebResponse { * @param $http_response_code null|int Forces the HTTP response code to the specified value. */ public function header( $string, $replace = true, $http_response_code = null ) { - list( $key, $val ) = explode( ":", $string, 2 ); + $match = array(); + if ( preg_match( '~^HTTP/1.\d (\d+)\D*$~', $string, $match ) ) { + $this->code = intval( $match[1] ); + } else { + list( $key, $val ) = explode( ":", $string, 2 ); - if( $replace || !isset( $this->headers[$key] ) ) { - $this->headers[$key] = $val; + if( $replace || !isset( $this->headers[$key] ) ) { + $this->headers[$key] = $val; + } + } + + if ( $http_response_code !== null ) { + $this->code = intval( $http_response_code ); } } @@ -100,6 +110,15 @@ class FauxResponse extends WebResponse { return $this->headers[$key]; } + /** + * Get the HTTP response code, null if not set + * + * @return Int or null + */ + public function getStatusCode() { + return $this->code; + } + /** * @param $name String: name of cookie * @param $value String: value to give cookie