MediaWiki  REL1_19
WebResponse.php
Go to the documentation of this file.
00001 <?php
00028 class WebResponse {
00029 
00037         public function header( $string, $replace = true, $http_response_code = null ) {
00038                 header( $string, $replace, $http_response_code );
00039         }
00040 
00049         public function setcookie( $name, $value, $expire = 0, $prefix = null, $domain = null ) {
00050                 global $wgCookiePath, $wgCookiePrefix, $wgCookieDomain;
00051                 global $wgCookieSecure,$wgCookieExpiration, $wgCookieHttpOnly;
00052                 if ( $expire == 0 ) {
00053                         $expire = time() + $wgCookieExpiration;
00054                 }
00055                 if( $prefix === null ) {
00056                         $prefix = $wgCookiePrefix;
00057                 }
00058                 if( $domain === null ) {
00059                         $domain = $wgCookieDomain;
00060                 }
00061                 $httpOnlySafe = wfHttpOnlySafe() && $wgCookieHttpOnly;
00062                 wfDebugLog( 'cookie',
00063                         'setcookie: "' . implode( '", "',
00064                                 array(
00065                                         $prefix . $name,
00066                                         $value,
00067                                         $expire,
00068                                         $wgCookiePath,
00069                                         $domain,
00070                                         $wgCookieSecure,
00071                                         $httpOnlySafe ) ) . '"' );
00072                 setcookie( $prefix . $name,
00073                         $value,
00074                         $expire,
00075                         $wgCookiePath,
00076                         $domain,
00077                         $wgCookieSecure,
00078                         $httpOnlySafe );
00079         }
00080 }
00081 
00085 class FauxResponse extends WebResponse {
00086         private $headers;
00087         private $cookies;
00088         private $code;
00089 
00096         public function header( $string, $replace = true, $http_response_code = null ) {
00097                 if ( substr( $string, 0, 5 ) == 'HTTP/' ) {
00098                         $parts = explode( ' ', $string, 3 );
00099                         $this->code = intval( $parts[1] );
00100                 } else {
00101                         list( $key, $val ) = array_map( 'trim', explode( ":", $string, 2 ) );
00102 
00103                         if( $replace || !isset( $this->headers[$key] ) ) {
00104                                 $this->headers[$key] = $val;
00105                         }
00106                 }
00107 
00108                 if ( $http_response_code !== null ) {
00109                         $this->code = intval( $http_response_code );
00110                 }
00111         }
00112 
00117         public function getheader( $key ) {
00118                 if ( isset( $this->headers[$key] ) ) {
00119                         return $this->headers[$key];
00120                 }
00121                 return null;
00122         }
00123 
00129         public function getStatusCode() {
00130                 return $this->code;
00131         }
00132 
00143         public function setcookie( $name, $value, $expire = 0, $prefix = null, $domain = null ) {
00144                 $this->cookies[$name] = $value;
00145         }
00146 
00151         public function getcookie( $name )  {
00152                 if ( isset( $this->cookies[$name] ) ) {
00153                         return $this->cookies[$name];
00154                 }
00155                 return null;
00156         }
00157 }