Serializes a Message entity.

@param Message $message
@param array   $options

@return array
174896
public function serialize(Message $message, array $options = [])
    {
        $userMessage = $this->getUserMessage($message);

        //mainly for tests or if someting went wrong
        if (!$userMessage) {
            $userMessage = new UserMessage();
        }

        $data = [
          'id' => $message->getUuid(),
          'object' => $message->getObject(),
          'content' => $message->getContent(),
          'to' => $message->getTo(),
          'meta' => [
            'date' => DateNormalizer::normalize($message->getDate()),
            'read' => $userMessage->isRead(),
            'removed' => $userMessage->isRemoved(),
            'sent' => $userMessage->isSent(),
            'umuuid' => $userMessage->getUuid(),
          ],
        ];

        $data['from'] = $message->getSender() ?
            $this->userSerializer->serialize($message->getSender(), [Options::SERIALIZE_MINIMAL]) :
            ['username' => $message->getSenderUsername()];

        if (in_array(Options::IS_RECURSIVE, $options)) {
            $data['children'] = array_map(function (Message $child) {
                return $this->serialize($child, $options);
            }, $message->getChildren()->toArray());
        }

        return $data;
    }
1141255
private function labeledMessage($label, $message, $options = 0)
    {
        if (isset($this->stdErr)) {
            $this->stdErr->writeln('<options=reverse>' . strtoupper($label) . '</> ' . $message, $options);
        }
    }
874428
public function debug($message = '', $options = 0)
    {
        $this->logger->debug($message);

        $this->write($message, $options);
        $this->write(PHP_EOL);

        return $this;
    }
1361330
public function buildMessagesValidationFields(
        array $fieldResults,
        array $messages = [],
        array $options = []
    ): array {
        foreach ($fieldResults as $fieldName => $validationResult) {
            $messages = $this->buildMessages(
                $fieldName,
                $validationResult,
                $messages,
                $options
            );
        }

        return $messages;
    }
971308
protected function encodeMessage($message, array $options = [])
    {
        $resolver = new OptionsResolver();
        $this->encoder->setDefaultOptions($resolver);
        $options = $resolver->resolve($options);

        return $this->encoder->encode($message, $this->compressor, $options);
    }
1307412
public function notify(Message $message, $options=array())
    {
        $logger = $GLOBALS['logger'];
        $logger->debug(
            'Sending Voice Message ',
            array(
             $message->getFrom(),
             $message->getBody(),
            )
        );
        $path    = 'notifications/voice/send';
        $request = $this->_remoteServer->post($path);
        $request->setPostField('type', 'sms');
        $request->setPostField('from', $message->getFrom());
        $request->setPostField('to', implode(';', $message->getRecipients()));
        $request->setPostField('content', $message->getBody());

        try {
            $response = $request->send();
            if ($response->getStatusCode() !== 200) {
                throw new MessagingException();
            }

            $rawResponse = $response->getBody('true');

            return $rawResponse;
        } catch (\Exception $e) {
            throw new MessagingException();
        }

    }
758961
public function serialize(Blog $blog, array $options = [])
    {
        return [
            'id' => $blog->getUuid(),
            'name' => $blog->getResourceNode()->getName(),
            'infos' => $blog->getInfos(),
            'options' => $this->blogOptionsSerializer->serialize($blog, $blog->getOptions()),
        ];
    }
598416
public function write($level, $message, $log_category = null, $options = array())
    {
        $default_option                  = [];
        $default_option['log_request']   = $this->_configRead('log_request');
        $default_option['log_post_data'] = $this->_configRead('log_post_data');
        $default_option['log_cookies']   = $this->_configRead('log_cookies');
        $default_option['log_session']   = $this->_configRead('log_session');
        $default_option['log_headers']   = $this->_configRead('log_headers');

        $options = array_merge($default_option, $options);

        $options['log_category']  = $log_category;

        return AlaxosLog::write($level, $message, $options);
    }
631045
public function startInsert($message, array $options = null) {
		return $this->startEvent($message, ProfileInterface::TYPE_INSERT, $options);
	}
1254421
public function sendNotification($channels, Message $message, $options=array())
    {
        $status = array();
        foreach ($channels as $channel) {
            $notifier = $this->_getNotifier($channel);
            if (empty($notifier) === false) {
                $status[$channel] = $notifier->notify($message, $options);
            }

            return $status;
        }

    }
731613
public function message($message, $options = null) {
		$options = $this->_mergeOptions($options);
		$options['message'] = $message;

		return $this->_View->element($options['element'], $options);
	}
968390
public static function DecryptMessage ($message, $key, $options = []) {
		$options['module'] = \MCRYPT_MODE_ECB;
		return static::Decrypt($message, $key, $options);
	}
485598
public function encode(Message $message, int $options = 0): string
    {
        $ctx = new Context($options);
        $qdCount = $anCount = $nsCount = $arCount = 0;

        foreach ($message->getQuestionRecords() as $record) {
            if (!$this->encodeQuestionRecord($ctx, $record)) {
                goto done;
            }

            $qdCount++;
        }

        foreach ($message->getAnswerRecords() as $record) {
            if (!$this->encodeResourceRecord($ctx, $record)) {
                goto done;
            }

            $anCount++;
        }

        foreach ($message->getAuthorityRecords() as $record) {
            if (!$this->encodeResourceRecord($ctx, $record)) {
                goto done;
            }

            $nsCount++;
        }

        foreach ($message->getAdditionalRecords() as $record) {
            if (!$this->encodeResourceRecord($ctx, $record)) {
                goto done;
            }

            $arCount++;
        }

        done:
        $packet = $this->encodeHeader($ctx, $message, $qdCount, $anCount, $nsCount, $arCount) . $ctx->data;

        if (!($options & EncodingOptions::FORMAT_TCP)) {
            \assert(
                \strlen($packet) <= 512,
                new \Error('UDP packet exceeds 512 byte limit: got ' . \strlen($packet) . ' bytes')
            );

            return $packet;
        }

        \assert(
            \strlen($packet) <= 65535,
            new \Error('TCP packet exceeds 65535 byte limit: got ' . \strlen($packet) . ' bytes')
        );

        return \pack('n', \strlen($packet)) . $packet;
    }
411980
public function serialize(LogConnectPlatform $log, array $options = [])
    {
        $serialized = [
            'id' => $log->getUuid(),
            'date' => $log->getConnectionDate()->format('Y-m-d\TH:i:s'),
            'duration' => $log->getDuration(),
            'user' => $this->serializer->serialize($log->getUser(), [Options::SERIALIZE_MINIMAL]),
        ];

        return $serialized;
    }
998829
public function message($message, $options = null) {
		$options = $this->_mergeOptions($options);

		$this->set($message, $options);

		$this->_assertSessionStackSize($options);
	}
493655
public function deserialize($data, Message $message, array $options = [])
    {
        $this->sipe('object', 'setObject', $data, $message);
        $this->sipe('content', 'setContent', $data, $message);
        $currentUser = $this->tokenStorage->getToken()->getUser();

        if (isset($data['parent'])) {
            $parent = $this->om->getRepository(Message::class)->find($data['parent']['id']);
            $message->setParent($parent);
        }

        if ($currentUser instanceof User && in_array(Options::CRUD_CREATE, $options)) {
            $message->setSender($currentUser);
        }

        //build the "to" string here
        //; is the separator
        //{} for groups
        //[] for workspaces
        $receivers = [];

        if (isset($data['toGroups'])) {
            $receivers = array_merge(array_map(function ($group) {
                return '{'.$group['name'].'}';
            }, $data['toGroups']), $receivers);
        }

        if (isset($data['toUsers'])) {
            $receivers = array_merge(array_map(function ($user) {
                return $user['username'];
            }, $data['toUsers']), $receivers);
        }

        if (isset($data['toWorkspaces'])) {
            $receivers = array_merge(array_map(function ($workspace) {
                return '['.$workspace['code'].']';
            }, $data['toWorkspaces']), $receivers);
        }

        $receiversString = implode(';', $receivers);

        if ('' !== $receiversString && !$message->getTo()) {
            $message->setTo($receiversString);
        }

        return $message;
    }
601107
public function publish(array $message, array $options = [])
    {
        $mergedOptions = $this->mergeOptions($options);

        if (isset($options['message_deduplication_id'])) {
            $mergedOptions['message_deduplication_id'] = $options['message_deduplication_id'];
        }

        if (isset($options['message_group_id'])) {
            $mergedOptions['message_group_id'] = $options['message_group_id'];
        }

        $options = $mergedOptions;

        $publishStart = microtime(true);

        // ensures that the SQS Queue and SNS Topic exist
        if (!$this->queueExists()) {
            $this->create();
        }

        if ($options['push_notifications']) {

            if (!$this->topicExists()) {
                $this->create();
            }

            $message    = [
                'default' => $this->getNameWithPrefix(),
                'sqs'     => json_encode($message),
                'http'    => $this->getNameWithPrefix(),
                'https'   => $this->getNameWithPrefix(),
            ];

            $result = $this->sns->publish([
                'TopicArn'         => $this->topicArn,
                'Subject'          => $this->getName(),
                'Message'          => json_encode($message),
                'MessageStructure' => 'json'
            ]);

            $context = [
                'TopicArn'           => $this->topicArn,
                'MessageId'          => $result->get('MessageId'),
                'push_notifications' => $options['push_notifications'],
                'publish_time'       => microtime(true) - $publishStart
            ];
            $this->log(200,"Message published to SNS", $context);

            return $result->get('MessageId');
        }

        $arguments = [
            'QueueUrl'      => $this->queueUrl,
            'MessageBody'   => json_encode($message),
            'DelaySeconds'  => $options['message_delay']
        ];

        if ($this->isQueueFIFO()) {
            if (isset($options['message_deduplication_id'])) {
                // Always use user supplied dedup id
                $arguments['MessageDeduplicationId'] = $options['message_deduplication_id'];
            } elseif ($options['content_based_deduplication'] !== true) {
                // If none is supplied and option "content_based_deduplication" is not set, generate default
                $arguments['MessageDeduplicationId'] = hash('sha256', json_encode($message));
            }

            $arguments['MessageGroupId'] = $this->getNameWithPrefix();
            if (isset($options['message_group_id'])) {
                $arguments['MessageGroupId'] = $options['message_group_id'];
            }
        }

        $result = $this->sqs->sendMessage($arguments);

        $context = [
            'QueueUrl'              => $this->queueUrl,
            'MessageId'             => $result->get('MessageId'),
            'push_notifications'    => $options['push_notifications'],
            'fifo'                  => $options['fifo']
        ];

        if ($this->isQueueFIFO()) {
            if (isset($arguments['MessageDeduplicationId'])) {
                $context['message_deduplication_id'] = $arguments['MessageDeduplicationId'];
            }
            $context['message_group_id'] = $arguments['MessageGroupId'];
        }

        $this->log(200,"Message published to SQS", $context);

        return $result->get('MessageId');
    }