Ensure that the message is in a correct format,
base64_encode the data, and error if the input is too wrong to proceed.

@param  array $message
@return array The message data
@throws \InvalidArgumentException
336693
private function formatMessage(array $message)
    {
        if (isset($message['data']) && $this->encode) {
            $message['data'] = base64_encode($message['data']);
        }

        if (!array_key_exists('data', $message) &&
            !array_key_exists('attributes', $message)) {
            throw new InvalidArgumentException('At least one of $data or
                $attributes must be specified on each message, but neither
                was given.');
        }

        return $message;
    }
306421
public function send($message)
    {
        if (!$message instanceof MailMessage) {
            throw new \InvalidArgumentException(
                sprintf('Mailer::%s expect instance of Swift_Message.', __FUNCTION__)
            );
        }

        return $this->swift->send($message, $this->failedRecipients);
    }
1099461
public function parse($message)
  {
    //Checking if the message is a full line
    if (strpos($message, "\r\n") === false) {
        return;
    }

    //Parsing the message
    if (!preg_match($this->messageRegex, $message, $parsed)) {
        $parsed = ['invalid' => $message];

        return $parsed;
    }

    /*
    * Raw message
    */
    $parsed['raw'] = $parsed[0];

    $parsed = $this->parseParameters($parsed);

    return $this->removeIntegerKeys($parsed);
  }
1043772
public function fromMessage($message)
    {
        static $parser;
        if (!$parser) {
            $parser = new MessageParser();
        }

        // Parse a response
        if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
            $data = $parser->parseResponse($message);
            return $this->createResponse(
                $data['code'],
                $data['headers'],
                $data['body'] === '' ? null : $data['body'],
                $data
            );
        }

        // Parse a request
        if (!($data = ($parser->parseRequest($message)))) {
            throw new \InvalidArgumentException('Unable to parse request');
        }

        return $this->createRequest(
            $data['method'],
            Url::buildUrl($data['request_url']),
            [
                'headers' => $data['headers'],
                'body' => $data['body'] === '' ? null : $data['body'],
                'config' => [
                    'protocol_version' => $data['protocol_version']
                ]
            ]
        );
    }
808743
private function prepareMessage($message) {
    return is_string($message) ? $message :
      (is_object($message) && method_exists($message, '__toString') ? $message->__toString() :
            StringUtil::getDump($message));
  }
327640
protected function formatMessage(array $data = [])
    {
        $params = array_merge($this->message, $data);

        foreach ($params as $key => $value) {
            if (in_array($key, $this->required, true) && empty($value) && empty($this->message[$key])) {
                throw new InvalidArgumentException(sprintf('Attribute "%s" can not be empty!', $key));
            }

            $params[$key] = empty($value) ? $this->message[$key] : $value;
        }

        $params['data'] = $this->formatData($params['data'] ?? []);

        return $params;
    }
569994
public function setMessageId($message)
    {
        if (is_bool($message)) {
            $this->_messageId = $message;
        } else {
            if (!preg_match('/^\<.+@.+\>$/', $message)) {
                throw new InvalidArgumentException('Invalid format to Message-ID. The text should be something like "<uuid@server.com>"');
            }
            $this->_messageId = $message;
        }

        return $this;
    }
286450
public function alias(array $message) {
    $message = $this->message($message);
    $message["type"] = "alias";

    return $this->consumer->alias($message);
  }
942947
public function prepareMessage($message)
    {
        list($text, $level, $category, $timestamp) = $message;

        $result = [
            'category' => $category,
            'level' => Logger::getLevelName($level),
            '@timestamp' => date('c', $timestamp),
        ];

        if (isset($message[4])) {
            $result['trace'] = $message[4];
        }

        //Exceptions get parsed into an array, text and arrays are passed as is, other types are var_dumped
        if ($text instanceof \Exception) {
            //convert exception to array for easier analysis
            $result['message'] = [
                'message' => $text->getMessage(),
                'file' => $text->getFile(),
                'line' => $text->getLine(),
                'trace' => $text->getTraceAsString(),
            ];
        } elseif (is_array($text) || is_string($text)) {
            $result['message'] = $text;
        } else {
            $result['message'] = VarDumper::export($text);
        }

        if ($this->includeContext) {
            $result['context'] = $this->getContextMessage();
        }

        $message = implode("\n", [
            Json::encode([
                'index' => new \stdClass()
            ]),
            Json::encode($result)
        ]);

        return $message;
    }
720515
protected function formatMessage($message)
    {
        if (is_array($message)) {
            $message = var_export($message, true);
        } elseif (is_object($message)) {
            $message = get_object_vars($message);
        }

        return $message;
    }
1269281
public function formatMessage($message)
    {
        if ($message instanceof \Exception || (interface_exists('\Throwable') && $message instanceof \Throwable)) {
            return $this->exceptionToString($message);
        } elseif ($message instanceof \JsonSerializable) {
            return json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        } elseif ($message instanceof \Serializable) {
            return serialize($message);
        } elseif (!is_array($message)) {
            return (string)$message;
        }

        if (!isset($message[0]) || !is_string($message[0])) {
            return json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        if (substr_count($message[0], '%') + 1 >= ($count = count($message)) && isset($message[$count - 1])) {
            foreach ((array)$message as $k => $v) {
                if ($k === 0 || is_scalar($v) || $v === null) {
                    continue;
                }

                if ($v instanceof \Exception || (interface_exists('\Throwable') && $v instanceof \Throwable)) {
                    $message[$k] = $this->exceptionToString($v);
                } elseif (is_array($v) || $v instanceof \JsonSerializable) {
                    $message[$k] = json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                }
            }
            /** @noinspection ArgumentUnpackingCanBeUsedInspection */
            return (string)call_user_func_array('sprintf', $message);
        }

        if (count($message) === 2) {
            if (isset($message[1]) && strpos($message[0], ':1') === false) {
                $message[0] = rtrim($message[0], ': ') . ': :1';
            }
        } elseif (count($message) === 3) {
            /** @noinspection NotOptimalIfConditionsInspection */
            if (isset($message[1], $message[2]) && strpos($message[0], ':1') === false && is_scalar($message[1])) {
                $message[0] = rtrim($message[0], ': ') . ': :1 => :2';
            }
        }

        $replaces = [];
        /** @noinspection ForeachSourceInspection */
        foreach ($message as $k => $v) {
            if ($k === 0) {
                continue;
            }

            if ($v instanceof \Exception || (interface_exists('\Throwable') && $v instanceof \Throwable)) {
                $v = $this->exceptionToString($v);
            } elseif (is_array($v) || $v instanceof \JsonSerializable) {
                $v = json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            } elseif ($v instanceof \Serializable) {
                $v = serialize($v);
            } elseif (is_string($v)) {
                null;
            } elseif ($v === null || is_scalar($v)) {
                $v = json_encode($v);
            } else {
                $v = (string)$v;
            }

            $replaces[":$k"] = $v;
        }

        return strtr($message[0], $replaces);
    }
998016
public function sendBatch(array $messages)
    {
        $body = '';
        /** @var Message\Message $message */
        foreach ($messages as $i => $message) {
            if (!$message instanceof Message\Message) {
                throw new InvalidArgumentException();
            }

            $body .= "[{$i}]\n";
            $body .= $message->toINI();
        }
        $body = trim($body);

        $request = $this->client->newRequest(
            'POST',
            $this->client->buildUriWithQuery('/SmSendPost.asp', ['encoding' => 'UTF8']),
            'text/plain',
            $body
        );

        $response = $this->client->sendRequest($request);

        return $this->parseMessageResponse($response);
    }
126166
protected function formatParams($message, $context)
    {
        if (!is_array($context)) {
            $context = array('context' => $context);
        }
        if ($message instanceof \Exception) {
            $context += array(
                'code' => $message->getCode(),
                'file' => $message->getFile(),
                'line' => $message->getLine(),
                'trace' => $message->getTraceAsString(),
            );
            $message = $message->getMessage();
        } elseif (is_array($message)) {
            $message = print_r($message, true);
        } else {
            $message = (string)$message;
        }
        return array('message' => $message, 'context' => $context);
    }
172823
private static function processParams(array $message): string
    {
        $msg_type = count($message);
        if($msg_type==1) {
            return (string) $message[0];
        } else if($msg_type<1) {
            return "";
        } else {
            $params = $message;
            $message = array_shift($params);
            return sprintf($message, ...$params);
        }
    }
1023936
protected function formatMessage($message)
    {
        $traces = array();
        foreach ($this->getBacktrace() as $trace) {
            $traces[] = "in {$trace['file']}:{$trace['line']}";
        }

        $str = "[" . date('Y-m-d H:i:s', time()) . "]#" .  $this->getUserIp() . "# - " . $message;
        $str .= (empty($traces) ? '' : "\n    " . implode("\n    ", $traces));
        return $str;
    }
858122
public function formatMessage(array $message): string
    {
        [$level, $text, $context] = $message;
        $category = $context['category'];
        $timestamp = $context['time'];
        $level = Logger::getLevelName($level);
        $traces = [];
        if (isset($context['trace'])) {
            foreach ($context['trace'] as $trace) {
                $traces[] = "in {$trace['file']}:{$trace['line']}";
            }
        }

        $prefix = $this->getMessagePrefix($message);

        return $this->getTime($timestamp) . " {$prefix}[$level][$category] $text"
            . (empty($traces) ? '' : "\n    " . implode("\n    ", $traces));
    }
817608
static public function encode($data)
	{
		if (is_array($data) || (is_object($data) && !method_exists($data, '_toString')))
		{
			throw new \InvalidArgumentException(__CLASS__ . ' can not handle an array or non-stringable object.');
		}

		return $data;
	}