Publishes multiple message at once

@param array $messages
@param array $options

@return array
960083
public function publishMessages(array $messages, array $options = [])
    {
        $options      = $this->mergeOptions($options);
        $publishStart = microtime(true);

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

        $encodedMessages = [];
        foreach ($messages as $message) {
            $encodedMessages[] = json_encode($message + ['_qpush_queue' => $this->name]);
        }

        $result = $this->ironmq->postMessages(
            $this->getNameWithPrefix(),
            $encodedMessages,
            [
                'timeout'       => $options['message_timeout'],
                'delay'         => $options['message_delay'],
                'expires_in'    => $options['message_expiration']
            ]
        );

        $context = [
            'message_ids'    => $result->ids,
            'publish_time'  => microtime(true) - $publishStart
        ];
        $this->log(200, "Messages have been published.", $context);

        return $result->ids;
    }
599505
public static function messages($messages = [], $append = true)
    {
        if (func_num_args()) {
            static::$_messages = $append ? array_merge(static::$_messages, $messages) : $messages + ['_default_' => 'is invalid'];
        }
        return static::$_messages;
    }
643868
protected function writeln($messages, $options = 0)
    {
        $this->log($messages);
        $this->output->writeln($messages, $options);
    }
946813
public function addMessages(array $messages, $prepend = false)
    {
        if ($prepend) {
            $messages = array_reverse($messages);
        }

        foreach ($messages as $message) {
            $this->addMessage($message, $prepend);
        }

        return $this;
    }
210639
public function listNotifications($options = array())
    {
        list($config) = $this->parseOptions($options, 'config');

        return $this->sendRequest(
            HttpMethod::GET,
            array(
                'config' => $config,
            ),
            '/notification'
        );
    }
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;
    }
940502
public function messages($messages = [], $append = true)
    {
        if (func_num_args()) {
            $this->_messages = $append ? array_merge($this->_messages, $messages) : $messages;
        }
        $checker = $this->_classes['checker'];
        return $this->_messages + $checker::messages();
    }
699555
public function appendMessage($message, $options = null, $internal_date = null) {
        return imap_append($this->client->getConnection(), $this->path, $message, $options, $internal_date);
    }
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();
        }

    }
969940
public function serialize(PlannedNotification $notification, array $options)
    {
        return [
            'id' => $notification->getUuid(),
            'message' => $this->messageSerializer->serialize($notification->getMessage()),
            'workspace' => $this->workspaceSerializer->serialize($notification->getWorkspace(), [Options::SERIALIZE_MINIMAL]),
            'parameters' => [
                'action' => $notification->getAction(),
                'interval' => $notification->getInterval(),
                'byMail' => $notification->isByMail(),
                'byMessage' => $notification->isByMessage(),
            ],
            'roles' => array_map(function (Role $role) {
                return $this->roleSerializer->serialize($role, [Options::SERIALIZE_MINIMAL]);
            }, $notification->getRoles()->toArray()),
        ];
    }
58626
public function send($message, array $options = [])
    {
        $config = Ioc::getConfig();

        if (empty($options['force']) && !$config->get('mail.enabled', true)) {
            return true;
        }

        if (\is_callable($message)) {
            $msgObject = $this->createMessage();

            $message = $message($msgObject, $this);

            if (!$message instanceof MailMessage) {
                $message = $msgObject;
            }
        }

        if (!$message instanceof MailMessage) {
            throw new \InvalidArgumentException(sprintf('Mail Message should instance of %s', MailMessage::class));
        }

        $this->triggerEvent('onMailerBeforeSend', [
            'message' => $message,
            'manager' => $this,
        ]);

        // Set default sender
        if (!$message->getFrom()) {
            if ($config->exists('mail.from.email')) {
                $message->from($config->get('mail.from.email'), $config->get('mail.from.name'));
            }
        }

        // CC/BCC
        if ($cc = $config->get('mail.cc')) {
            if (is_string($cc)) {
                $cc = array_filter(array_map('trim', explode(',', $cc)), 'strlen');
            }

            $message->cc($cc);
        }

        if ($bcc = $config->get('mail.bcc')) {
            if (is_string($bcc)) {
                $bcc = array_filter(array_map('trim', explode(',', $bcc)), 'strlen');
            }

            $message->bcc($bcc);
        }

        $result = $this->getAdapter()->send($message);

        $this->triggerEvent('onMailerAfterSend', [
            'message' => $message,
            'manager' => $this,
            'result' => &$result,
        ]);

        return $result;
    }
423823
public function deserialize($data, Message $message, array $options)
    {
        if (!in_array(Options::REFRESH_UUID, $options)) {
            $message->setUuid($data['id']);
        }

        $this->sipe('title', 'setTitle', $data, $message);
        $this->sipe('content', 'setContent', $data, $message);

        if (isset($data['workspace']['uuid'])) {
            $workspace = $this->workspaceRepo->findOneBy(['uuid' => $data['workspace']['uuid']]);

            if (!empty($workspace)) {
                $message->setWorkspace($workspace);
            }
        }

        return $message;
    }
1143826
public function success(string $message, string $title = '', array $options = []): self
    {
        return $this->addNotification(self::SUCCESS, $message, $title, $options);
    }
1126381
protected function buildSentryData(Message $message, array $options)
    {
        $properties = $message->getProperties();

        $data = [
            'tags' => [
                'routing_key' => $properties['routing_key'] ?? '',
                'queue' => $options['queue'] ?? '',
            ],
            'extra' => [
                'message' => $message->getBody(),
            ],
        ];

        return $data;
    }
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;
    }
296130
public function checkMessages(array $options = [])
    {
        $this->buildBody($options);

        $rawMessages = json_decode($this->getRequest()->getBody()->getContents());

        return $this->makeMessages($rawMessages->data);
    }
461679
public function setMessages(array $messages)
    {
        return tap($this, function ($instance) use ($messages) {
            $instance->messages = [$instance->messagesWrapper => $messages];
        });
    }