54 $session =
null, $protocol =
'http'
56 $this->requestTime = microtime(
true );
58 if ( is_array(
$data ) ) {
61 throw new MWException(
"FauxRequest() got bogus data" );
64 if ( $session instanceof
MediaWiki\Session\Session ) {
65 $this->sessionId = $session->getSessionId();
66 } elseif ( is_array( $session ) ) {
67 $mwsession = SessionManager::singleton()->getEmptySession( $this );
68 $this->sessionId = $mwsession->getSessionId();
69 foreach ( $session as $key => $value ) {
70 $mwsession->set( $key, $value );
72 } elseif ( $session !==
null ) {
73 throw new MWException(
"FauxRequest() got bogus session" );
90 public function getText( $name, $default =
'' ) {
91 # Override; don't recode since we're using internal data
92 return (
string)$this->
getVal( $name, $default );
107 return $this->
wasPosted ?
'POST' :
'GET';
114 return $this->wasPosted;
117 public function getCookie( $key, $prefix =
null, $default =
null ) {
118 if ( $prefix ===
null ) {
122 $name = $prefix . $key;
123 return $this->cookies[$name] ?? $default;
132 public function setCookie( $key, $value, $prefix =
null ) {
133 $this->
setCookies( [ $key => $value ], $prefix );
142 if ( $prefix ===
null ) {
146 foreach (
$cookies as $key => $value ) {
147 $name = $prefix . $key;
148 $this->cookies[$name] = $value;
175 'name' =>
$data->getName(),
176 'type' =>
$data->getType(),
177 'tmp_name' =>
$data->getTempName(),
178 'size' =>
$data->getSize(),
179 'error' =>
$data->getError(),
183 if ( !is_array(
$data ) ||
186 throw new MWException( __METHOD__ .
' got bogus data' );
188 $this->uploadData[$key] =
$data;
206 $this->requestUrl = $url;
215 if ( $this->requestUrl ===
null ) {
218 return $this->requestUrl;
222 return $this->protocol;
238 foreach (
$headers as $name => $val ) {
239 $name = strtoupper( $name );
240 $this->headers[$name] = $val;
248 if ( $this->sessionId !==
null ) {
249 return iterator_to_array( $this->
getSession() );
255 return $this->
wasPosted ? $this->data : [];
$wgCookiePrefix
Cookies generated by MediaWiki have names starting with this prefix.
Object to fake the $_FILES array.
WebRequest clone which takes values from a provided array.
getPostValues()
Get the values passed via POST.
setCookie( $key, $value, $prefix=null)
getText( $name, $default='')
getRawPostString()
FauxRequests shouldn't depend on raw request data (but that could be implemented here)
initHeaders()
Initialise the header list.
getRawInput()
FauxRequests shouldn't depend on raw request data (but that could be implemented here)
setCookies( $cookies, $prefix=null)
getProtocol()
Get the current URL protocol (http or https)
getUpload( $key)
Return a FauxRequestUpload object corresponding to the key.
getMethod()
Get the HTTP method used for this request.
setUpload( $key, $data)
Set fake upload data for one file with specific key.
__construct( $data=[], $wasPosted=false, $session=null, $protocol='http')
getCookie( $key, $prefix=null, $default=null)
Get a cookie from the $_COOKIE jar.
getRawQueryString()
FauxRequests shouldn't depend on raw request data (but that could be implemented here)
setUploadData( $uploadData)
Set fake upload data for all files.
Object to access the $_FILES array.
const REQUIRED_FILEINFO_KEYS
All keys a fileinfo has to specific to work with this class.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
string $protocol
Cached URL protocol.
getSession()
Return the session for this request.
getVal( $name, $default=null)
Fetch a text string and partially normalized it.
string[] $headers
Lazy-initialized request headers indexed by upper-case header name.
array $data
The parameters from $_GET, $_POST and the path router.