/** * @since 1.17 * * @param string|string[]|MessageSpecifier $key Message key, or array of * message keys to try and use the first non-empty message for, or a * MessageSpecifier to copy from. * @param array $params Message parameters. * @param Language $language Optional language of the message, defaults to $wgLang. * * @throws InvalidArgumentException */ public function __construct($key, $params = array(), Language $language = null) { global $wgLang; if ($key instanceof MessageSpecifier) { if ($params) { throw new InvalidArgumentException('$params must be empty if $key is a MessageSpecifier'); } $params = $key->getParams(); $key = $key->getKey(); } if (!is_string($key) && !is_array($key)) { throw new InvalidArgumentException('$key must be a string or an array'); } $this->keysToTry = (array) $key; if (empty($this->keysToTry)) { throw new InvalidArgumentException('$key must not be an empty list'); } $this->key = reset($this->keysToTry); $this->parameters = array_values($params); $this->language = $language ?: $wgLang; }
/** * @since 1.17 * @param string|string[]|MessageSpecifier $key Message key, or array of * message keys to try and use the first non-empty message for, or a * MessageSpecifier to copy from. * @param array $params Message parameters. * @param Language $language [optional] Language to use (defaults to current user language). * @throws InvalidArgumentException */ public function __construct($key, $params = [], Language $language = null) { if ($key instanceof MessageSpecifier) { if ($params) { throw new InvalidArgumentException('$params must be empty if $key is a MessageSpecifier'); } $params = $key->getParams(); $key = $key->getKey(); } if (!is_string($key) && !is_array($key)) { throw new InvalidArgumentException('$key must be a string or an array'); } $this->keysToTry = (array) $key; if (empty($this->keysToTry)) { throw new InvalidArgumentException('$key must not be an empty list'); } $this->key = reset($this->keysToTry); $this->parameters = array_values($params); // User language is only resolved in getLanguage(). This helps preserve the // semantic intent of "user language" across serialize() and unserialize(). $this->language = $language ?: false; }