MediaWiki master
ApiMessage.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Api;
22
26
33class ApiMessage extends Message implements IApiMessage {
35
49 public static function create( $msg, $code = null, array $data = null ) {
50 if ( is_array( $msg ) ) {
51 // From StatusValue
52 if ( isset( $msg['message'] ) ) {
53 $msg = [ $msg['message'], ...$msg['params'] ?? [] ];
54 }
55
56 // Weirdness that comes in sometimes, including the above
57 if ( $msg[0] instanceof MessageSpecifier ) {
58 $msg = $msg[0];
59 }
60 }
61
62 if ( $msg instanceof IApiMessage ) {
63 return $msg;
64 } elseif ( $msg instanceof RawMessage ) {
65 return new ApiRawMessage( $msg, $code, $data );
66 } else {
67 return new ApiMessage( $msg, $code, $data );
68 }
69 }
70
79 public function __construct( $msg, $code = null, array $data = null ) {
80 if ( $msg instanceof Message ) {
81 foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
82 if ( isset( $msg->$key ) ) {
83 $this->$key = $msg->$key;
84 }
85 }
86 } elseif ( is_array( $msg ) ) {
87 $key = array_shift( $msg );
88 parent::__construct( $key, $msg );
89 } else {
90 parent::__construct( $msg );
91 }
92 $this->setApiCode( $code, $data );
93 }
94}
95
97class_alias( ApiMessage::class, 'ApiMessage' );
Extension of Message implementing IApiMessage.
__construct( $msg, $code=null, array $data=null)
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
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:150
string $key
The message key.
Definition Message.php:198
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.