MediaWiki master
ApiMessage.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Api;
8
12
19class ApiMessage extends Message implements IApiMessage {
21
35 public static function create( $msg, $code = null, ?array $data = null ) {
36 if ( is_array( $msg ) ) {
37 // From StatusValue
38 if ( isset( $msg['message'] ) ) {
39 $msg = [ $msg['message'], ...$msg['params'] ?? [] ];
40 }
41
42 // Weirdness that comes in sometimes, including the above
43 if ( $msg[0] instanceof MessageSpecifier ) {
44 $msg = $msg[0];
45 }
46 }
47
48 if ( $msg instanceof IApiMessage ) {
49 return $msg;
50 } elseif ( $msg instanceof RawMessage ) {
51 return new ApiRawMessage( $msg, $code, $data );
52 } else {
53 return new ApiMessage( $msg, $code, $data );
54 }
55 }
56
65 public function __construct( $msg, $code = null, ?array $data = null ) {
66 if ( $msg instanceof Message ) {
67 foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
68 if ( isset( $msg->$key ) ) {
69 $this->$key = $msg->$key;
70 }
71 }
72 } elseif ( is_array( $msg ) ) {
73 $key = array_shift( $msg );
74 parent::__construct( $key, $msg );
75 } else {
76 parent::__construct( $msg );
77 }
78 $this->setApiCode( $code, $data );
79 }
80}
81
83class_alias( ApiMessage::class, 'ApiMessage' );
Extension of Message implementing IApiMessage.
static create( $msg, $code=null, ?array $data=null)
Create an IApiMessage for the message.
__construct( $msg, $code=null, ?array $data=null)
Extension of RawMessage implementing IApiMessage.
Variant of the Message class.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
string $key
The message key.
Definition Message.php:192
trait ApiMessageTrait
Trait to implement the IApiMessage interface for Message subclasses.
Interface for messages with machine-readable data for use by the API.
setApiCode( $code, ?array $data=null)
Sets the machine-readable code for use by the API.