MediaWiki master
ApiRawMessage.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Api;
8
10
17class ApiRawMessage extends RawMessage implements IApiMessage {
19
29 public function __construct( $msg, $code = null, ?array $data = null ) {
30 if ( $msg instanceof RawMessage ) {
31 foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
32 if ( isset( $msg->$key ) ) {
33 $this->$key = $msg->$key;
34 }
35 }
36 } elseif ( is_array( $msg ) ) {
37 $key = array_shift( $msg );
38 parent::__construct( $key, $msg );
39 } else {
40 parent::__construct( $msg );
41 }
42 $this->setApiCode( $code, $data );
43 }
44
46 public function getApiCode() {
47 if ( $this->apiCode === null ) {
48 // Copied from ApiMessageTrait to avoid changing the error codes. This causes T350248,
49 // but there's nothing better we can do when a RawMessage is used.
50 $this->apiCode = preg_replace( '/[^a-zA-Z0-9_-]/', '_', $this->getTextOfRawMessage() );
51 }
52 return $this->apiCode;
53 }
54}
55
57class_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.If no code was specifically set,...
Variant of the Message class.
string $key
The message key.
Definition Message.php:192
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