Go to the documentation of this file.
7 use InvalidArgumentException;
20 const CT_HTML =
'text/html; charset=utf-8';
41 $json = json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
42 if ( $json ===
false ) {
64 public function createJson( $value, $contentType =
null ) {
67 $response->setHeader(
'Content-Type', $contentType );
170 if ( $errorCode < 400 || $errorCode >= 600 ) {
171 throw new InvalidArgumentException(
'error code must be 4xx or 5xx' );
174 'httpCode' => $errorCode,
197 $exception->getMessageValue() );
201 $exception->getCode(),
203 [
'message' => $exception->getMessage() ],
204 (array)$exception->getErrorData()
209 'message' =>
'Error: exception of type ' . get_class( $exception ),
226 $originalValue = $value;
227 if ( is_scalar( $value ) ) {
228 $data = [
'value' => $value ];
229 } elseif ( is_array( $value ) || $value instanceof stdClass ) {
232 $type = gettype( $originalValue );
233 if (
$type ===
'object' ) {
234 $type = get_class( $originalValue );
236 throw new InvalidArgumentException( __METHOD__ .
": Invalid return value type $type" );
249 $response->setHeader(
'Content-Type', self::CT_HTML );
250 $response->setHeader(
'Location', $target );
261 $url = htmlspecialchars( $url );
262 return "<!doctype html><title>Redirect</title><a href=\"$url\">$url</a>";
266 if ( !$this->textFormatters ) {
271 foreach ( $this->textFormatters as $formatter ) {
273 $messageText = $formatter->format( $messageValue );
274 $translations[
$lang] = $messageText;
276 return [
'messageTranslations' => $translations ];
if(!isset( $args[0])) $lang
static getStructuredExceptionData( $e, $catcher=self::CAUGHT_BY_OTHER)
Get a structured representation of an Exception.
Handler class for MWExceptions.
static getMessage( $code)
Get the message associated with an HTTP response status code.
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Methods for dealing with language codes.