MediaWiki master
ApiMessage.php
Go to the documentation of this file.
1<?php
22
29class ApiMessage extends Message implements IApiMessage {
31
45 public static function create( $msg, $code = null, array $data = null ) {
46 if ( is_array( $msg ) ) {
47 // From StatusValue
48 if ( isset( $msg['message'] ) ) {
49 $msg = [ $msg['message'], ...$msg['params'] ?? [] ];
50 }
51
52 // Weirdness that comes in sometimes, including the above
53 if ( $msg[0] instanceof MessageSpecifier ) {
54 $msg = $msg[0];
55 }
56 }
57
58 if ( $msg instanceof IApiMessage ) {
59 return $msg;
60 } elseif ( $msg instanceof RawMessage ) {
61 return new ApiRawMessage( $msg, $code, $data );
62 } else {
63 return new ApiMessage( $msg, $code, $data );
64 }
65 }
66
75 public function __construct( $msg, $code = null, array $data = null ) {
76 if ( $msg instanceof Message ) {
77 foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
78 if ( isset( $msg->$key ) ) {
79 $this->$key = $msg->$key;
80 }
81 }
82 } elseif ( is_array( $msg ) ) {
83 $key = array_shift( $msg );
84 parent::__construct( $key, $msg );
85 } else {
86 parent::__construct( $msg );
87 }
88 $this->setApiCode( $code, $data );
89 }
90}
setApiCode( $code, array $data=null)
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.
trait ApiMessageTrait
Trait to implement the IApiMessage interface for Message subclasses.
Interface for messages with machine-readable data for use by the API.