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