28use InvalidArgumentException;
47 private $uploadData = [];
62 $this->requestTime = microtime(
true );
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 InvalidArgumentException(
"MediaWiki\Request\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 ) {
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 ) {
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 InvalidArgumentException( __METHOD__ .
' got bogus data' );
190 $this->uploadData[$key] =
$data;
208 $this->requestUrl = $url;
215 if ( $this->requestUrl ===
null ) {
218 return $this->requestUrl;
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 : [];
294class_alias( FauxRequest::class,
'FauxRequest' );
A class containing constants representing the names of configuration variables.
const CookiePrefix
Name constant for the CookiePrefix setting, for use with Config::get()