Prechecks to prevent multiple usage
@param string $message message to be sent
@param string $senderID originator ID
551280
protected function preChecks($message, $senderID)
    {
        //TODO a better method for this
        //Pre-checks act1
        if ($senderID == null || !strlen(trim($senderID))) {
            $this->senderID = $this->config['default_sender'];
        } else {
            $this->senderID = $senderID;
        }

        //Pre-checks act2
        if ($message == null || !strlen(trim($message))) {
            $this->message = '&'; //Error character for sms
        } else {
            $this->message = $message;
        }
    }
1018186
public function critical($message = '', $context = [], $role = 'system', $times = 0, $ttl = 0)
    {
        if ($this->isSingle()) {
            $this->log($message, $context, Logger::CRITICAL, $role, $times, $ttl);
        }
    }
572193
public function UserModel_BeforeSaveSerialized_Handler($Sender) {
      if (Gdn::Session()->CheckPermission('Plugins.Flagging.Notify')) {
         if ($Sender->EventArguments['Column'] == 'Preferences' && is_array($Sender->EventArguments['Name'])) {
            // Shorten our arguments
            $UserID = $Sender->EventArguments['UserID'];
            $Prefs = $Sender->EventArguments['Name'];
            $FlagPref = GetValue('Email.Flag', $Prefs, NULL);
            
            if ($FlagPref !== NULL) {
               // Add or remove user from config array
               $NotifyUsers = C('Plugins.Flagging.NotifyUsers', array());
               $IsNotified = array_search($UserID, $NotifyUsers); // beware '0' key
               if ($IsNotified !== FALSE && !$FlagPref) {
                  // Remove from NotifyUsers
                  unset($NotifyUsers[$IsNotified]);
               }
               elseif ($IsNotified === FALSE && $FlagPref) {
                  // Add to NotifyUsers
                  $NotifyUsers[] = $UserID;
               }
               
               // Save new list of users to notify
               SaveToConfig('Plugins.Flagging.NotifyUsers', array_values($NotifyUsers));
            }
         }
      }
   }
592059
protected function beforeSendPerformed(Swift_Mime_Message $message)
    {
        $event = new Swift_Events_SendEvent($this, $message);

        foreach ($this->plugins as $plugin) {

            if (method_exists($plugin, 'beforeSendPerformed')) {

                $plugin->beforeSendPerformed($event);

            }
        }
    }
1052209
protected function log_warning($courseid, $competencyid, $cmid, $message) {
        $this->warnings[] = array(
            'courseid' => $courseid,
            'competencyid' => $competencyid,
            'cmid' => $cmid,
            'message' => $message
        );
    }
1127700
public function onPipeMessage(Server $server, int $srcWorkerId, string $message)
    {
        /* @var PipeMessageInterface $pipeMessage */
        $pipeMessage = App::getBean(PipeMessage::class);
        list($type, $data) = $pipeMessage->unpack($message);

        App::trigger(AppEvent::PIPE_MESSAGE, null, $type, $data, $srcWorkerId);
    }
923315
private String GCMGetFreshToken(final String senderID) {
        getConfigLogger().verbose(getAccountId(), "GcmManager: Requesting a GCM token for Sender ID - " + senderID);
        String token = null;
        try {
            token = InstanceID.getInstance(context)
                    .getToken(senderID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            getConfigLogger().info(getAccountId(), "GCM token : " + token);
        } catch (Throwable t) {
            getConfigLogger().verbose(getAccountId(), "GcmManager: Error requesting GCM token", t);
        }
        return token;
    }
405561
public function writeLog($message, $priority='LOG_INFO')
    {
        $this->logger->addRecord(
            self::$_mapping[$priority],
            $this->_transform($message)
        );

    }
1250763
public function beforeSendPerformed(Swift_Events_SendEvent $event)
    {
        $message = $event->getMessage();

        $to = $this->filterEmailArray((array) $message->getTo());
        $cc = $this->filterEmailArray((array) $message->getCc());
        $bcc = $this->filterEmailArray((array) $message->getBcc());

        $message->setTo($to);
        $message->setCc($cc);
        $message->setBcc($bcc);

        $all = $to + $cc + $bcc;

        if (empty($all)) {
            $event->cancelBubble();
        }
    }
398426
public function unreference(string $watcherId)
    {
        if (!isset($this->watchers[$watcherId])) {
            return;
        }

        $this->watchers[$watcherId]->referenced = false;
    }
919774
public function forExpectedCondition(WebDriverExpectedCondition $expectedCondition, $message = "")
    {
        $this->getBrowser()->wait($this->timeOutInSeconds)->until($expectedCondition, $message);
    }
22511
public function send(Message $message) : void
    {
        $destination = $this->getRedirectURL($message);
        Utils::getContainer()->redirect($destination);
    }
1020550
public function setMessage($message, $priority)
    {
        $this->message = (string) $message;
        $this->priority = (int) $priority;
    }
750725
public function removeMessagePackageReceived(\Sopinet\ChatBundle\Entity\MessagePackage $messagePackageReceived)
    {
        $this->messagesPackageReceived->removeElement($messagePackageReceived);
    }
19026
public function validate(Message $message)
    {
        /** @var Validator $validator */
        foreach ($this->validators as $validator) {
            $validator->validate($message);
        }
    }
275767
public function check(Criteria $criteria, Message $message)
    {
        foreach ($criteria as $criterium) {
            if ($criterium instanceof Criteria) {
                if (!$this->check($criterium, $message)) {
                    return false;
                }

                return true;
            } elseif (!$criterium instanceof Criterium) {
                throw new InvalidArgumentException('Criterium is neither of type Criterium nor Criteria. Type is '.gettype($criterium));
            }

            $type = $criterium->getType();
            $value = $criterium->getValue();

            if (!strlen($value)) {
                continue;
            }

            switch ($type) {
                case Criteria::CRITERIUM_SUBJECT_LIKE:
                    if (stristr($message->getSubject(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_SUBJECT_NOT_LIKE:
                    if (stristr($message->getSubject(), $value) !== false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_BODY_LIKE:
                    if (stristr($message->getBody(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_BODY_NOT_LIKE:
                    if (stristr($message->getBody(), $value) !== false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_IS:
                    if ($message->getPriority() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_MIN:
                    if ($message->getPriority() < $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_IN:
                    if (!in_array($message->getPriority(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_TYPE_IS:
                    if ($message->getType() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_TYPE_IN:
                    if (!in_array($message->getType(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_IS:
                    if ($message->getChannel() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_LIKE:
                    if (stristr($message->getChannel(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_IN:
                    if (!in_array($message->getChannel(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_ROLE_IS:
                    if ($message->getRole() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_ROLE_IN:
                    if (!in_array($message->getRole(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_MAX_AGE:
                    if ($message->getCreatedAt()->format('U') < (time() - ($value * 24 * 60 * 60))) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_MIN_AGE:
                    if ($message->getCreatedAt()->format('U') > (time() - ($value * 24 * 60 * 60))) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_START_DATE:
                    if ($message->getCreatedAt()->format('U') < strtotime($value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_END_DATE:
                    if ($message->getCreatedAt()->format('U') > strtotime($value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_DATE_IS:
                    if ($message->getCreatedAt()->format('Y-m-d') !== date('Y-m-d', strtotime($value))) {
                        continue 2;
                    }
                    break;

                default:
                    continue 2;
                    break;
            }

            return true;
        }

        return false;
    }
1301572
def _messageFromSender(self, sender, messageID):
        
        return self.store.findUnique(
            _QueuedMessage,
            AND(_QueuedMessage.senderUsername == sender.localpart,
                _QueuedMessage.senderDomain == sender.domain,
                _QueuedMessage.messageID == messageID),
            default=None)