MediaWiki REL1_35
ApiMessage.php
Go to the documentation of this file.
1<?php
27class ApiMessage extends Message implements IApiMessage {
29
42 public static function create( $msg, $code = null, array $data = null ) {
43 if ( is_array( $msg ) ) {
44 // From StatusValue
45 if ( isset( $msg['message'] ) ) {
46 if ( isset( $msg['params'] ) ) {
47 $msg = array_merge( [ $msg['message'] ], $msg['params'] );
48 } else {
49 $msg = [ $msg['message'] ];
50 }
51 }
52
53 // Weirdness that comes in sometimes, including the above
54 if ( $msg[0] instanceof MessageSpecifier ) {
55 $msg = $msg[0];
56 }
57 }
58
59 if ( $msg instanceof IApiMessage ) {
60 return $msg;
61 } elseif ( $msg instanceof RawMessage ) {
62 return new ApiRawMessage( $msg, $code, $data );
63 } else {
64 return new ApiMessage( $msg, $code, $data );
65 }
66 }
67
76 public function __construct( $msg, $code = null, array $data = null ) {
77 if ( $msg instanceof Message ) {
78 foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
79 if ( isset( $msg->$key ) ) {
80 $this->$key = $msg->$key;
81 }
82 }
83 } elseif ( is_array( $msg ) ) {
84 $key = array_shift( $msg );
85 parent::__construct( $key, $msg );
86 } else {
87 parent::__construct( $msg );
88 }
89 $this->setApiCode( $code, $data );
90 }
91}
setApiCode( $code, array $data=null)
Extension of Message implementing IApiMessage @newable.
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 @newable.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:161
string $key
The message key.
Definition Message.php:203
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.
Stable for implementing.