MediaWiki master
ApiRawMessage.php
Go to the documentation of this file.
1<?php
22
29class ApiRawMessage extends RawMessage implements IApiMessage {
31
41 public function __construct( $msg, $code = null, array $data = null ) {
42 if ( $msg instanceof RawMessage ) {
43 foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
44 if ( isset( $msg->$key ) ) {
45 $this->$key = $msg->$key;
46 }
47 }
48 } elseif ( is_array( $msg ) ) {
49 $key = array_shift( $msg );
50 parent::__construct( $key, $msg );
51 } else {
52 parent::__construct( $msg );
53 }
54 $this->setApiCode( $code, $data );
55 }
56
57 public function getApiCode() {
58 if ( $this->apiCode === null ) {
59 // Copied from ApiMessageTrait to avoid changing the error codes. This causes T350248,
60 // but there's nothing better we can do when a RawMessage is used.
61 $this->apiCode = preg_replace( '/[^a-zA-Z0-9_-]/', '_', $this->getTextOfRawMessage() );
62 }
63 return $this->apiCode;
64 }
65}
Extension of RawMessage implementing IApiMessage.
__construct( $msg, $code=null, array $data=null)
getApiCode()
Returns a machine-readable code for use by the API.
Variant of the Message class.
string $key
The message key.
Definition Message.php:206
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.