38 private $wasPosted =
false;
42 private $uploadData = [];
56 $session =
null, $protocol =
'http'
58 $this->requestTime = microtime(
true );
60 if ( is_array(
$data ) ) {
63 throw new MWException(
"FauxRequest() got bogus data" );
66 if ( $session instanceof
MediaWiki\Session\Session ) {
67 $this->sessionId = $session->getSessionId();
68 } elseif ( is_array( $session ) ) {
69 $mwsession = SessionManager::singleton()->getEmptySession( $this );
70 $this->sessionId = $mwsession->getSessionId();
71 foreach ( $session as $key => $value ) {
72 $mwsession->set( $key, $value );
74 } elseif ( $session !==
null ) {
75 throw new MWException(
"FauxRequest() got bogus session" );
92 public function getText( $name, $default =
'' ) {
93 # Override; don't recode since we're using internal data
94 return (
string)$this->
getVal( $name, $default );
109 return $this->
wasPosted ?
'POST' :
'GET';
116 return $this->wasPosted;
119 public function getCookie( $key, $prefix =
null, $default =
null ) {
120 if ( $prefix ===
null ) {
121 $cookiePrefix = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::CookiePrefix );
122 $prefix = $cookiePrefix;
124 $name = $prefix . $key;
125 return $this->cookies[$name] ?? $default;
134 public function setCookie( $key, $value, $prefix =
null ) {
135 $this->
setCookies( [ $key => $value ], $prefix );
144 if ( $prefix ===
null ) {
145 $cookiePrefix = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::CookiePrefix );
146 $prefix = $cookiePrefix;
148 foreach (
$cookies as $key => $value ) {
149 $name = $prefix . $key;
150 $this->cookies[$name] = $value;
161 foreach ( $uploadData as $key =>
$data ) {
177 'name' =>
$data->getName(),
178 'type' =>
$data->getType(),
179 'tmp_name' =>
$data->getTempName(),
180 'size' =>
$data->getSize(),
181 'error' =>
$data->getError(),
185 if ( !is_array(
$data ) ||
188 throw new MWException( __METHOD__ .
' got bogus data' );
190 $this->uploadData[$key] =
$data;
208 $this->requestUrl = $url;
217 if ( $this->requestUrl ===
null ) {
220 return $this->requestUrl;
224 return $this->protocol;
240 foreach (
$headers as $name => $val ) {
241 $name = strtoupper( $name );
242 $this->headers[$name] = $val;
250 if ( $this->sessionId !==
null ) {
251 return iterator_to_array( $this->
getSession() );
257 return $this->
wasPosted ? $this->data : [];
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.
A class containing constants representing the names of configuration variables.
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.