From 584c5510f045e5154a53022c0e38460750b87019 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 6 Sep 2008 08:58:24 +0000 Subject: [PATCH] Add session accessor functions to WebRequest --- includes/WebRequest.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 46816e4ef5..2c2a049e79 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -637,6 +637,18 @@ class WebRequest { } } } + + /* + * Get data from $_SESSION + */ + function getSessionData( $key ) { + if( !isset( $_SESSION[$key] ) ) + return null; + return $_SESSION[$key]; + } + function setSessionData( $key, $data ) { + $_SESSION[$key] = $data; + } } /** @@ -652,7 +664,7 @@ class FauxRequest extends WebRequest { * fake GET/POST values * @param $wasPosted Bool: whether to treat the data as POST */ - function FauxRequest( $data, $wasPosted = false ) { + function FauxRequest( $data, $wasPosted = false, $session ) { if( is_array( $data ) ) { $this->data = $data; } else { @@ -660,6 +672,11 @@ class FauxRequest extends WebRequest { } $this->wasPosted = $wasPosted; $this->headers = array(); + $this->session = $session; + } + + function notImplemented( $method ) { + throw new MWException( "{$method}() not implemented" ); } function getText( $name, $default = '' ) { @@ -680,15 +697,24 @@ class FauxRequest extends WebRequest { } function getRequestURL() { - throw new MWException( 'FauxRequest::getRequestURL() not implemented' ); + $this->notImplemented( __METHOD__ ); } function appendQuery( $query ) { - throw new MWException( 'FauxRequest::appendQuery() not implemented' ); + $this->notImplemented( __METHOD__ ); } function getHeader( $name ) { return isset( $this->headers[$name] ) ? $this->headers[$name] : false; } + function getSessionData( $key ) { + if( !isset( $this->session[$key] ) ) + return null; + return $this->session[$key]; + } + function setSessionData( $key, $data ) { + $this->notImplemented( __METHOD__ ); + } + } -- 2.20.1