X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMessage.php;h=c7752aac240b549a28663b9f99735d62f57c7d4f;hb=f58fa20d9c4cd46a00b17042ba74fb17110b5125;hp=fd016fcb371de8368b7509248cfbf8ec092a88ee;hpb=4d39e688aaa0c890901f3a5f574363d9aa1ef144;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Message.php b/includes/Message.php index fd016fcb37..c7752aac24 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -382,6 +382,32 @@ class Message implements MessageSpecifier, Serializable { return new self( $key, $params ); } + /** + * Transform a MessageSpecifier or a primitive value used interchangeably with + * specifiers (a message key string, or a key + params array) into a proper Message + * @param string|array|MessageSpecifier $value + * @return Message + * @throws InvalidArgumentException + * @since 1.27 + */ + public static function newFromSpecifier( $value ) { + if ( $value instanceof RawMessage ) { + $message = new RawMessage( $value->getKey(), $value->getParams() ); + } elseif ( $value instanceof MessageSpecifier ) { + $message = new Message( $value ); + } elseif ( is_array( $value ) ) { + $key = array_shift( $value ); + $message = new Message( $key, $value ); + } elseif ( is_string( $value ) ) { + $message = new Message( $value ); + } else { + throw new InvalidArgumentException( __METHOD__ . ': invalid argument type ' + . gettype( $value ) ); + } + + return $message; + } + /** * Factory function accepting multiple message keys and returning a message instance * for the first message which is non-empty. If all messages are empty then an