Serialize message to logger context

@param MessageInterface $message

@return array
776165
private function messageLoggerContext(MessageInterface $message): array
    {
        return [
            'id' => $message->getId(),
            'created' => $message->getCreated(),
            'type' => $message->getType(),
            'payload' => $message->getPayload(),
        ];
    }
605177
public function extractMessages(array $log = null)
    {
        if (true === empty($log)) {
            return array();
        }

        $this->extractor->setMessageGroups($this->config['message_groups']);

        return $this->extractor->setLog($log)
            ->extract();
    }
1002260
private function getAttachmentsAsArrays(Message $message): array
    {
        $attachments = [];

        foreach ($message->getAttachments() as $attachment) {
            $attachments[] = $attachment->toArray();
        }

        return $attachments;
    }
1365570
public static function prepareMessage($message)
    {
        if (method_exists($message, '__toString')) {
            return $message->__toString();
        }

        if (is_scalar($message)) {
            return (string)$message;
        }

        if (class_exists(VarDumper::class)) {
            return VarDumper::export($message);
        }

        throw new InvalidArgumentException('The log message MUST be a string or object implementing __toString()');
    }
1020276
private function getUserMessages(Message $message)
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        return $this->om->getRepository(UserMessage::class)->findBy(['message' => $message, 'user' => $currentUser]);
    }
974211
private function formMessageData(Message $message)
    {
        $data = array(
            'registration_ids' => $message->getRegistrationIds(),
        );

        $dataFields = array(
            'registration_ids' => 'getRegistrationIds',
            'collapse_key' => 'getCollapseKey',
            'data' => 'getData',
            'notification' => 'getNotification',
            'delay_while_idle' => 'getDelayWhileIdle',
            'time_to_live' => 'getTtl',
            'restricted_package_name' => 'getRestrictedPackageName',
            'dry_run' => 'getDryRun',
            'content_available' => 'getContentAvailable',
            'priority' => 'getPriority',
        );

        foreach ($dataFields as $fieldName => $getter) {
            if ($message->$getter() != null) {
                $data[$fieldName] = $message->$getter();
            }
        }

        return $data;
    }
773717
protected function stringifyMessage($message)
    {
        if (is_array($message) || is_object($message) || is_bool($message)) {
            return (string)var_export($message, true);
        }
        return (string)$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;
    }
879274
public function log($message)
    {
        $app = Base::instance();
        if ($app['LOG_FILE']) {
            if (null === $this->logger) {
                $this->logger = new Log($app['LOG_FILE']);
            }
            $this->logger->write($message);
        }

        return $this;
    }
310495
public function log($message, $context = null, $logType = null)
    {
        if (is_int($context) and is_null($logType)) {
            $logType = $context;
            $context = array();
        }

        if (!is_array($context)) {
            $context = is_null($context) ? array() : array($context);
        }

        if (!is_int($logType)) {
            $logType = self::INFO;
        }

        return call_user_func(array($this->instance, $this->logTypes[$logType]), $message, $context);
    }
620439
private function dispatch(MessageInterface $message): bool
    {
        $type = $message->getType();

        if (!$this->hasHandlers($type)) {
            return true;
        }

        $result = true;

        foreach ($this->handlers[$type] as $handler) {
            $handlerResult = $this->handleMessage($handler, $message);

            if ($result && !$handlerResult) {
                $result = false;
            }
        }

        return $result;
    }
922156
public function transformMaterial(AbstractMessage $message)
    {
        $type = $message->getType();

        return [
            'msgtype' => $type,
            $type     => [
                'media_id' => $message->get('media_id'),
            ],
        ];
    }
332416
public function send(MessageInterface $message)
    {
        if (!$message instanceof AndroidMessage) {
            throw new InvalidMessageTypeException(sprintf("Message type '%s' not supported by C2DM", get_class($message)));
        }

        if ($this->getAuthToken()) {
            $headers[] = "Authorization: GoogleLogin auth=" . $this->authToken;
            $data = $message->getMessageBody();

            $buzz = new Browser();
            $buzz->getClient()->setVerifyPeer(false);
            $buzz->getClient()->setTimeout($this->timeout);
            $response = $buzz->post("https://android.apis.google.com/c2dm/send", $headers, http_build_query($data));

            return preg_match("/^id=/", $response->getContent()) > 0;
        }

        return false;
    }
909287
protected function formatMessage( LogMessage $message )
    {
        return $this->macro_processor->addHandler(
            function($keyword) use($message){
                switch($keyword){
                    case 'LEVEL':
                        return $message->getLevel();
                    case 'TAG':
                        return $message->getTag();
                    case 'MESSAGE':
                        return $this->convertEncoding( $message->getMessage() );
                    case 'FILE':
                    case 'FILENAME':
                        return $message->getFile();
                    case 'LINE':
                        return $message->getLine();
                }
                return null;
            }
        )->process($this->log_format);
    }
528034
private function getNestedMessages(Message $message, Schema $schema): array
    {
        $messages = [];

        foreach ($schema->getFields() as $field) {
            if (!$field->getType()->isMessage()) {
                continue;
            }

            if (!$message->has($field->getName())) {
                continue;
            }

            if ($field->isASingleValue()) {
                $messages[] = $message->get($field->getName());
            } else {
                $messages = array_merge($messages, array_values($message->get($field->getName())));
            }
        }

        return $messages;
    }
1218822
public function parseResponse($message)
    {
        if (!($parts = $this->parseMessage($message))) {
            return false;
        }

        list($protocol, $version) = explode('/', trim($parts['start_line'][0]));

        return [
            'protocol'         => $protocol,
            'protocol_version' => $version,
            'code'             => $parts['start_line'][1],
            'reason_phrase'    => isset($parts['start_line'][2]) ? $parts['start_line'][2] : '',
            'headers'          => $parts['headers'],
            'body'             => $parts['body']
        ];
    }
1357324
private static function format(MessageInterface $message, $main)
    {
        $result  = "\r\n-------------";
        $result .= "\r\n{$main}";

        foreach ($message->getHeaders() as $name => $values) {
            $result .= "\r\n{$name}: " . implode(', ', $values);
        }

        $result .= "\r\n\r\n{$message->getBody()}";
        $result .= "\r\n-------------";

        return $result;
    }