MediaWiki REL1_34
|
Generates standardized response objects. More...
Public Member Functions | |
__construct ( $textFormatters) | |
create () | |
Create an unspecified response. | |
createFromException ( $exception) | |
Turn an exception into a JSON error response. | |
createFromReturnValue ( $value) | |
Create a JSON response from an arbitrary value. | |
createHttpError ( $errorCode, array $bodyData=[]) | |
Create a HTTP 4xx or 5xx response. | |
createJson ( $value, $contentType=null) | |
Create a successful JSON response. | |
createLegacyTemporaryRedirect ( $target) | |
Creates a temporary (302) redirect. | |
createLocalizedHttpError ( $errorCode, MessageValue $messageValue) | |
Create an HTTP 4xx or 5xx response with error message localisation. | |
createNoContent () | |
Create a 204 (No Content) response, used to indicate that an operation which does not return anything (e.g. | |
createNotModified () | |
Create a 304 (Not Modified) response, used when the client has an up-to-date cached response. | |
createPermanentRedirect ( $target) | |
Creates a permanent (301) redirect. | |
createSeeOther ( $target) | |
Creates a See Other (303) redirect. | |
createTemporaryRedirect ( $target) | |
Creates a temporary (307) redirect. | |
encodeJson ( $value) | |
Encode a stdClass object or array to a JSON string. | |
formatMessage (MessageValue $messageValue) | |
Public Attributes | |
const | CT_HTML = 'text/html; charset=utf-8' |
const | CT_JSON = 'application/json' |
const | CT_PLAIN = 'text/plain; charset=utf-8' |
Protected Member Functions | |
createRedirectBase ( $target) | |
Create a redirect response with type / response code unspecified. | |
getHyperLink ( $url) | |
Returns a minimal HTML document that links to the given URL, as suggested by RFC 7231 for 3xx responses. | |
Private Attributes | |
ITextFormatter[] | $textFormatters |
Generates standardized response objects.
Definition at line 18 of file ResponseFactory.php.
MediaWiki\Rest\ResponseFactory::__construct | ( | $textFormatters | ) |
ITextFormatter[] | $textFormatters |
Definition at line 29 of file ResponseFactory.php.
References MediaWiki\Rest\ResponseFactory\$textFormatters.
MediaWiki\Rest\ResponseFactory::create | ( | ) |
Create an unspecified response.
It is the caller's responsibility to set specifics like response code, content type etc.
Definition at line 53 of file ResponseFactory.php.
MediaWiki\Rest\ResponseFactory::createFromException | ( | $exception | ) |
Turn an exception into a JSON error response.
Exception | Throwable | $exception |
Definition at line 194 of file ResponseFactory.php.
References $response, MediaWiki\Rest\ResponseFactory\createHttpError(), and MediaWiki\Rest\ResponseFactory\createLocalizedHttpError().
MediaWiki\Rest\ResponseFactory::createFromReturnValue | ( | $value | ) |
Create a JSON response from an arbitrary value.
This is a fallback; it's preferable to use createJson() instead.
mixed | $value | A structure containing only scalars, arrays and stdClass objects |
InvalidArgumentException | When $value cannot be reasonably represented as JSON |
Definition at line 225 of file ResponseFactory.php.
References $response, $type, and MediaWiki\Rest\ResponseFactory\createJson().
MediaWiki\Rest\ResponseFactory::createHttpError | ( | $errorCode, | |
array | $bodyData = [] ) |
Create a HTTP 4xx or 5xx response.
int | $errorCode | HTTP error code |
array | $bodyData | An array of data to be included in the JSON response |
InvalidArgumentException |
Definition at line 169 of file ResponseFactory.php.
References $response, and MediaWiki\Rest\ResponseFactory\createJson().
Referenced by MediaWiki\Rest\ResponseFactory\createFromException(), and MediaWiki\Rest\ResponseFactory\createLocalizedHttpError().
MediaWiki\Rest\ResponseFactory::createJson | ( | $value, | |
$contentType = null ) |
Create a successful JSON response.
array | stdClass | $value | JSON value |
string | null | $contentType | HTTP content type (should be 'application/json+...') or null for plain 'application/json' |
Definition at line 64 of file ResponseFactory.php.
References $response, MediaWiki\Rest\ResponseFactory\CT_JSON, and MediaWiki\Rest\ResponseFactory\encodeJson().
Referenced by MediaWiki\Rest\ResponseFactory\createFromReturnValue(), and MediaWiki\Rest\ResponseFactory\createHttpError().
MediaWiki\Rest\ResponseFactory::createLegacyTemporaryRedirect | ( | $target | ) |
Creates a temporary (302) redirect.
HTTP 302 was underspecified and has been superseded by 303 (when the redirected request should be a GET, regardless of what the current request is) and 307 (when the method should not be changed), but might still be needed for HTTP 1.0 clients or to match legacy behavior.
string | $target | Redirect target (an absolute URL) |
Definition at line 112 of file ResponseFactory.php.
References $response, and MediaWiki\Rest\ResponseFactory\createRedirectBase().
MediaWiki\Rest\ResponseFactory::createLocalizedHttpError | ( | $errorCode, | |
MessageValue | $messageValue ) |
Create an HTTP 4xx or 5xx response with error message localisation.
Definition at line 185 of file ResponseFactory.php.
References MediaWiki\Rest\ResponseFactory\createHttpError(), and MediaWiki\Rest\ResponseFactory\formatMessage().
Referenced by MediaWiki\Rest\ResponseFactory\createFromException().
MediaWiki\Rest\ResponseFactory::createNoContent | ( | ) |
Create a 204 (No Content) response, used to indicate that an operation which does not return anything (e.g.
a PUT request) was successful.
Headers are generally interpreted to refer to the target of the operation. E.g. if this was a PUT request, the caller of this method might want to add an ETag header describing the created resource.
Definition at line 81 of file ResponseFactory.php.
References $response.
MediaWiki\Rest\ResponseFactory::createNotModified | ( | ) |
Create a 304 (Not Modified) response, used when the client has an up-to-date cached response.
Per RFC 7232 the response should contain all Cache-Control, Content-Location, Date, ETag, Expires, and Vary headers that would have been sent with the 200 OK answer if the requesting client did not have a valid cached response. This is the responsibility of the caller of this method.
Definition at line 156 of file ResponseFactory.php.
References $response.
MediaWiki\Rest\ResponseFactory::createPermanentRedirect | ( | $target | ) |
Creates a permanent (301) redirect.
This indicates that the caller of the API should update their indexes and call the new URL in the future. 301 redirects tend to get cached and are hard to undo. Client behavior for methods other than GET/HEAD is not well-defined and this type of response should be avoided in such cases.
string | $target | Redirect target (an absolute URL) |
Definition at line 96 of file ResponseFactory.php.
References $response, and MediaWiki\Rest\ResponseFactory\createRedirectBase().
|
protected |
Create a redirect response with type / response code unspecified.
string | $target | Redirect target (an absolute URL) |
Definition at line 247 of file ResponseFactory.php.
References $response, and MediaWiki\Rest\ResponseFactory\getHyperLink().
Referenced by MediaWiki\Rest\ResponseFactory\createLegacyTemporaryRedirect(), MediaWiki\Rest\ResponseFactory\createPermanentRedirect(), MediaWiki\Rest\ResponseFactory\createSeeOther(), and MediaWiki\Rest\ResponseFactory\createTemporaryRedirect().
MediaWiki\Rest\ResponseFactory::createSeeOther | ( | $target | ) |
Creates a See Other (303) redirect.
This indicates that the target resource might be of interest to the client, without necessarily implying that it is the same resource. The client will always use GET (or HEAD) when following the redirection. Useful for GET-after-POST.
string | $target | Redirect target (an absolute URL) |
Definition at line 140 of file ResponseFactory.php.
References $response, and MediaWiki\Rest\ResponseFactory\createRedirectBase().
MediaWiki\Rest\ResponseFactory::createTemporaryRedirect | ( | $target | ) |
Creates a temporary (307) redirect.
This indicates that the operation the client was trying to perform can temporarily be achieved by using a different URL. Clients will preserve the request method when retrying the request with the new URL.
string | $target | Redirect target (an absolute URL) |
Definition at line 126 of file ResponseFactory.php.
References $response, and MediaWiki\Rest\ResponseFactory\createRedirectBase().
MediaWiki\Rest\ResponseFactory::encodeJson | ( | $value | ) |
Encode a stdClass object or array to a JSON string.
array | stdClass | $value |
JsonEncodingException |
Definition at line 40 of file ResponseFactory.php.
Referenced by MediaWiki\Rest\ResponseFactory\createJson().
MediaWiki\Rest\ResponseFactory::formatMessage | ( | MessageValue | $messageValue | ) |
Definition at line 265 of file ResponseFactory.php.
References $lang.
Referenced by MediaWiki\Rest\ResponseFactory\createLocalizedHttpError().
|
protected |
Returns a minimal HTML document that links to the given URL, as suggested by RFC 7231 for 3xx responses.
string | $url | An absolute URL |
Definition at line 260 of file ResponseFactory.php.
Referenced by MediaWiki\Rest\ResponseFactory\createRedirectBase().
|
private |
Definition at line 24 of file ResponseFactory.php.
Referenced by MediaWiki\Rest\ResponseFactory\__construct().
const MediaWiki\Rest\ResponseFactory::CT_HTML = 'text/html; charset=utf-8' |
Definition at line 20 of file ResponseFactory.php.
const MediaWiki\Rest\ResponseFactory::CT_JSON = 'application/json' |
Definition at line 21 of file ResponseFactory.php.
Referenced by MediaWiki\Rest\ResponseFactory\createJson().
const MediaWiki\Rest\ResponseFactory::CT_PLAIN = 'text/plain; charset=utf-8' |
Definition at line 19 of file ResponseFactory.php.