43 private $wasPosted =
false;
47 private $uploadData = [];
63 $this->requestTime = microtime(
true );
65 if ( is_array(
$data ) ) {
68 throw new MWException(
"MediaWiki\Request\FauxRequest() got bogus data" );
71 if ( $session instanceof
MediaWiki\Session\Session ) {
72 $this->sessionId = $session->getSessionId();
73 } elseif ( is_array( $session ) ) {
74 $mwsession = SessionManager::singleton()->getEmptySession( $this );
75 $this->sessionId = $mwsession->getSessionId();
76 foreach ( $session as $key => $value ) {
77 $mwsession->set( $key, $value );
79 } elseif ( $session !==
null ) {
80 throw new MWException(
"MediaWiki\Request\FauxRequest() got bogus session" );
97 public function getText( $name, $default =
'' ) {
98 # Override; don't recode since we're using internal data
99 return (
string)$this->
getVal( $name, $default );
114 return $this->
wasPosted ?
'POST' :
'GET';
121 return $this->wasPosted;
124 public function getCookie( $key, $prefix =
null, $default =
null ) {
125 if ( $prefix ===
null ) {
127 $prefix = $cookiePrefix;
129 $name = $prefix . $key;
130 return $this->cookies[$name] ?? $default;
139 public function setCookie( $key, $value, $prefix =
null ) {
140 $this->
setCookies( [ $key => $value ], $prefix );
149 if ( $prefix ===
null ) {
151 $prefix = $cookiePrefix;
153 foreach (
$cookies as $key => $value ) {
154 $name = $prefix . $key;
155 $this->cookies[$name] = $value;
166 foreach ( $uploadData as $key =>
$data ) {
182 'name' =>
$data->getName(),
183 'type' =>
$data->getType(),
184 'tmp_name' =>
$data->getTempName(),
185 'size' =>
$data->getSize(),
186 'error' =>
$data->getError(),
190 if ( !is_array(
$data ) ||
193 throw new MWException( __METHOD__ .
' got bogus data' );
195 $this->uploadData[$key] =
$data;
213 $this->requestUrl = $url;
222 if ( $this->requestUrl ===
null ) {
225 return $this->requestUrl;
245 foreach (
$headers as $name => $val ) {
246 $name = strtoupper( $name );
247 $this->headers[$name] = $val;
255 if ( $this->sessionId !==
null ) {
256 return iterator_to_array( $this->
getSession() );
262 return $this->
wasPosted ? $this->data : [];
298class_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()
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.