Generates number of notifications by message recipient count
and notification service limitations

@param MessageInterface $message
@return \ArrayIterator
428699
public function buildNotifications(MessageInterface $message)
    {
        $notifications  = new \ArrayIterator();
        $recipientQueue = new \SplQueue();
        $recipientChunk = new \ArrayIterator();

        foreach ($message->getRecipientDeviceCollection() as $recipient) {
            $recipientChunk->append($recipient);

            if ($recipientChunk->count() >= $message->getMaxRecipientsPerMessage()) {
                $recipientQueue->enqueue($recipientChunk);
                $recipientChunk = new \ArrayIterator();
            }
        }

        if ($recipientChunk->count()) {
            $recipientQueue->enqueue($recipientChunk);
        }

        while (!$recipientQueue->isEmpty()) {
            $notification = $this->createNotification($recipientQueue->dequeue(), $message);
            $notifications->append($notification);
        }

        return $notifications;
    }
1199025
public function getNotifierForMessage(Message $message): Notifier
    {
        foreach ($this->notifiers as $notifier) {
            if ($notifier->handles($message)) {
                return $notifier;
            }
        }
        throw new NotifierNotFoundException();
    }
1270517
public function setMessage(MessageInterface $message = null): ValidatorRuleInterface
    {
        $this->message = $message ?? $this->setupDefaultMessage();
        
        return $this;
    }
935185
public function send(MailMessageInterface $message) : stdClass
    {
        return $this->mailer->sendMessage($this->domain, $message->getData());
    }
147240
public function preProcessMessage(MessageInterface $message)
    {
        foreach ($this->getProcessorStore()->getProcessors() as $processor) {
            $message = $processor->preProcessMessage($message);
        }

        return $message;
    }
1013053
public function split(Message $message) : array
    {
        $splittedMessages = [];
        $messageName      = $message->getHeaders()->get(MessageFlowModule::INTEGRATION_MESSAGING_CQRS_MESSAGE_NAME_HEADER);

        foreach($this->messageFlowMapper->getFlowRegistrationsFor($messageName) as $messageFlowRegistration) {
            $registrationMessage     = MessageBuilder::fromMessage($message)
                ->setHeader(MessageFlowModule::INTEGRATION_MESSAGING_CQRS_MESSAGE_FLOW_REGISTRATION_HEADER, $messageFlowRegistration);

            if (!$messageFlowRegistration->isExternalFlow()) {
                $registrationMessage = $registrationMessage
                    ->setHeader(MessageFlowModule::INTEGRATION_MESSAGING_CQRS_MESSAGE_CLASS_HEADER, $messageFlowRegistration->getMessageClassName());
            }

            $splittedMessages[] = $registrationMessage
                                    ->build();
        }

        return $splittedMessages;
    }
868464
public function withMessage(string $message): PayloadInterface
    {
        if ($this->message === $message) {
            return $this;
        }

        $clone = clone $this;
        $clone->message = $message;

        return $clone;
    }
819963
public function sendTo(Recipient $recipient, MessageInterface $message)
    {
        $driver = "\\Eyewitness\\Eye\\Notifications\\Drivers\\".ucfirst(strtolower($recipient->type));

        if (class_exists($driver)) {
            $channel = app($driver);
            $channel->fire($recipient, $message);
        } else {
            app(Eye::class)->logger()->debug('Notification Driver does not exist', $driver);
        }
    }
7987
protected function getRecipients($notifiable, $notification, $message)
    {
        if (is_string($recipients = $notifiable->routeNotificationFor('mail', $notification))) {
            $recipients = [$recipients];
        }

        return collect($recipients)->mapWithKeys(function ($recipient, $email) {
            return is_numeric($email)
                    ? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
                    : [$email => $recipient];
        })->all();
    }
970462
public function queue(Message $message)
	{
		// Bump the message ID
		$this->lastMessageId++;

		// Put the message in an envelope
		$envelope = new MessageEnvelope($this->lastMessageId, $message);

		// Save the message so we can update it later on
		$this->storeMessageEnvelope($envelope);

		// Queue and return the envelope
		$this->logger->debug('Queuing Apns\Message #' . $this->lastMessageId . ' to device "' . $message->getDeviceToken() . '" on Apns\Gateway with certificate "' . $this->getCertificate()->getDescription() . '"');
		$this->sendQueue->enqueue($envelope);

		return $envelope;
	}
111576
public static function getMessageSize(MessageInterface $message, $default = null)
    {
        $bodySize = $message->getBody()->getSize();

        if (null === $bodySize) {
            return $default;
        }

        $firstLine = '';

        if ($message instanceof ServerRequestInterface) {
            $firstLine = self::getRequestLine($message);
        } elseif ($message instanceof ResponseInterface) {
            $firstLine = self::getResponseLine($message);
        }

        $headers = [];

        foreach ($message->getHeaders() as $header => $values) {
            foreach ($values as $value) {
                $headers[] = sprintf('%s: %s', $header, $value);
            }
        }

        $headersSize = strlen(implode("\r\n", $headers));

        return strlen($firstLine) + 2 + $headersSize + 4 + $bodySize;
    }
1164186
public function send(MessageInterface $message, $skipErrors = true) {

        // check clickatell limit
        if (count($message->getRecipients()) > 600) {
            $this->addError(new SendingError($message->getRecipients(),
                    'You have excedded provider limit of messages to send in one time.'
                    , $message->error));
        }

        $gateway = $this->getClient();

        try {
            $response = $gateway->sendMessage($message->getRecipients(), $message->getText());
            foreach ($response as $message) {
                if ($message->errorCode) {
                    $this->addError(new SendingError($message->destination, $message->errorCode, $message->error));
                }
            }
        }
        catch (Exception $e) {
            $this->addError(new SendingError('', $e->getCode(), $e->getMessage()));
            if (!$skipErrors) {
                throw new \RuntimeException($e->getMessage(), $e->getCode());
            }
        }
        return $this->getErrors()->count() === 0;
    }
528633
public function attach(MessageInterface $message)
    {

        // force handling the timer tasks now
        $this->synchronized(function (MessageQueue $self, MessageInterface $m) {
            // create a unique identifier for the priority
            $priority = $this->uniqueWorkerName($m->getPriority());

            // load the worker for the message's priority
            if (isset($self->workers[$priority])) {
                // attach the message
                $self->messages[$m->getMessageId()] = $m;

                // store the job-ID and the PK of the message => necessary to load the message later
                $jobWrapper = new \stdClass();
                $jobWrapper->jobId = $m->getMessageId();
                $jobWrapper->messageId = $m->getMessageId();

                // attach the job to the worker
                $self->workers[$priority]->attach($jobWrapper);
            }

        }, $this, $message);
    }
961723
public function notify_problem($message) {
        $n = new \core\output\notification($message, \core\output\notification::NOTIFY_ERROR);
        return $this->render($n);
    }
1260481
private function getMessageLineCount($message)
    {
        $messageLength = FormatterHelper::strlenWithoutDecoration($this->output->getFormatter(), $message);

        return ceil($messageLength / $this->getTerminalWidth());
    }
577693
protected function numberOfRecipients(Swift_Mime_Message $message)
    {
        return count(array_merge(
            (array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
        ));
    }
350724
public static function count($message = '') {
		if (!self::$_enabled) {
			return;
		}

		if (self::$ensureByGet && !isset($_GET['debug'])) {
			return;
		}

		/* Get a new ADEBUG object */
		$debug = new THEDEBUG\ADEBUG(array(1));

		/* And its ID (calculated using file and line) */
		$ID = $debug->getID();

		/*
		 * just increment the counter and return if this is		
		 * not the first time called from this file and line,
		 */
		if (isset(self::$counts[$ID])) {
			unset($debug);
			self::$counts[$ID]->variable++;
			return;
		}

		/* Register output on destruction */
		$debug->putOnDestruction = true;

		/* Generate the message or insert the passed one */
		if (empty($message)) {
			$debug->name = sprintf(
				'File %s, Line %s was visited',
				$debug->file,
				$debug->line
			);
		} else {
			$debug->name = $message;
		}

		/* Register callback to add time/s to the counter */
		$debug->addCallback('beforePut', function (&$debug) {
			if ($debug->variable === 1) {
				$debug->variable .= ' time.';
			} else {
				$debug->variable .= ' times.';
			}
		});

		/* Add the debug to the collection of counts */
		self::$counts[$ID] = $debug;
	}