Find an email template and create a swift message.

@param string $reference
@param mixed  $to
@param array  $parameters
@param string $locale

@throws \RuntimeException

@return \Swift_Message
766504
public function get($reference, $to, array $parameters = array(), $locale = null)
    {
        try {
            $email = $this->getEmail($reference);
            return $this->generateMessage($email, $to, $parameters, $locale);
        } catch (ReferenceNotFoundException $e) {
            return $this->generateExceptionMessage($reference);
        }
    }
157838
public function sendTemplateMessageByType($touser, $type, $data, $url = null) {
		return isset($this->templates[$type]) && $this->sendTemplateMessage($touser, $this->templates[$type], $data, $url);
	}
1036187
public function sendMessage($to, $plaintext, $force_plain = false)
    {
        if (extension_loaded('curve25519') && extension_loaded('protobuf') && !$force_plain) {
            $to_num = ExtractNumber($to);
            if (!(strpos($to, '-') !== false)) {
                if (!$this->axolotlStore->containsSession($to_num, 1)) {
                    $this->sendGetCipherKeysFromUser($to_num);
                }

                $sessionCipher = $this->getSessionCipher($to_num);

                if (in_array($to_num, $this->v2Jids) && !isset($this->v1Only[$to_num])) {
                    $version = '2';
                    $alteredText = padMessage($plaintext);
                } else {
                    $version = '1';
                    $alteredText = $plaintext;
                }
                $cipherText = $sessionCipher->encrypt($alteredText);

                if ($cipherText instanceof WhisperMessage) {
                    $type = 'msg';
                } else {
                    $type = 'pkmsg';
                }
                $message = $cipherText->serialize();
                $msgNode = new ProtocolNode('enc',
              [
                'v'     => $version,
                'type'  => $type,
              ], null, $message);
            } else {
                /* if (in_array($to, $this->v2Jids))
          {
            $version = "2";
            $plaintext = padMessage($plaintext);
          }
          else
            $version = "1";

          if(!$this->axolotlStore->containsSenderKey($to)){
            $gsb = new GroupSessionBuilder($this->axolotlStore);
            $senderKey = $gsb->process ($groupId, $keyId, $iteration, $chainKey, $signatureKey)
          }
          $thi*/
          $msgNode = new ProtocolNode('body', null, null, $plaintext);
            }
        } else {
            $msgNode = new ProtocolNode('body', null, null, $plaintext);
        }
        $plaintextNode = new ProtocolNode('body', null, null, $plaintext);
        $id = $this->sendMessageNode($to, $msgNode, null, $plaintextNode);

        if ($this->messageStore !== null) {
            $this->messageStore->saveMessage($this->phoneNumber, $to, $plaintext, $id, time());
        }

        return $id;
    }
802066
public function sendMessage($to, $subject, $view, $params = [])
    {
        if (empty($to)) {
            return false;
        }
        /** @var \yii\mail\BaseMailer $mailer */
        $mailer = Yii::$app->mailer;
        $mailer->viewPath = $this->mailViewPath;
        $mailer->getView()->theme = Yii::$app->view->theme;
        $message = $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)->setTo($to)->setSubject($subject);
        if ($this->mailSender != null) {
            $message->setFrom($this->mailSender);
        }
        return $message->send();
    }
951091
public static function _x($message, $context, $params = [], $language = null)
    {
        return Yii::t($context, $message, $params, $language);
    }
750560
protected function translateMessage($message, array $parameters = array())
    {
        return $this->translator->trans($message, $parameters, $this->transDomain);
    }
440683
protected function createMessage($to)
    {
        $message = (new \Swift_Message())
            ->setSubject($this->messageParts['subject'])
            ->setFrom($this->fromEmail, $this->fromName)
            ->setTo($to)
        ;
        if (!empty($this->replyToEmail)) {
            $message->setReplyTo($this->replyToEmail);
        }
        if (!empty($this->bccAddresses)) {
            foreach ($this->bccAddresses as $email => $name) {
                $message->addBcc($email, $name);
            }
        }
        if (!empty($this->messageParts['body_html'])) {
            $message->setBody($this->messageParts['body_html'], 'text/html');
        }
        // don't add if plain text version is empty string when trimmed
        if (trim($this->messageParts['body_text']) != '') {
            $message->addPart($this->messageParts['body_text'], 'text/plain');
        }

        return $message;
    }
109909
public function setTo($to)
    {
        if ($to instanceof Email) {
            $to = [$to];
        }

        foreach ($to as $email) {
            if (!$email instanceof Email) {
                throw new MailerException('Email must be an instance of \Webiny\Component\Mailer\Email.');
            }
            $this->addTo($email);
        }

        return $this;
    }
742896
protected function makeCall(TwilioCallMessage $message, $to)
    {
        $params = [
            'url' => trim($message->content),
        ];

        $this->fillOptionalParams($params, $message, [
            'statusCallback',
            'statusCallbackMethod',
            'method',
            'status',
            'fallbackUrl',
            'fallbackMethod',
        ]);

        if (! $from = $this->getFrom($message)) {
            throw CouldNotSendNotification::missingFrom();
        }

        return $this->twilioService->calls->create(
            $to,
            $from,
            $params
        );
    }
473476
public function setTextMessage(array $to,
                                   string $subject,
                                   string $body,
                                   array $attachment = null,
                                   array $cc = null,
                                   array $bcc = EMAIL_BCC): void
    {
        $this->email->setFrom($this->from);
        foreach ($to as $value) {
            $this->email->addTo($value);
        }
        if ($cc != null) {
            foreach ($cc as $value) {
                $this->email->addCc($value);
            }
        }
        if ($bcc != null) {
            foreach ($bcc as $value) {
                $this->email->addBcc($value);
            }
        }
        if ($attachment != null) {
            foreach ($attachment as $file) {
                $this->email->addAttachment($file);
            }
        }
        $this->email->setSubject($subject);
        $this->email->setBody($body);
    }
1314511
public function trans($id, array $parameters = [], $domain = null, $locale = null)
    {
        $domain = $domain ?? $this->config->getDefaultDomain();
        $locale = $locale ?? $this->locale;

        $message = $this->get($locale, $domain, $id);

        return self::interpolate($message, $parameters);
    }
1077455
public static function compose(string $message, ...$parameters): string
    {
        $translation = static::getTranslation($message);
        $result      = empty($parameters) === false ? \vsprintf($translation, $parameters) : $translation;

        return $result;
    }
732855
public function trans($id, array $parameters = [], $domain = null, $locale = null)
    {
        if (null === $locale) {
            $locale = $this->getLocale();
        }

        if (null === $domain) {
            $domain = 'messages';
        }

        if (!isset($this->catalogues[$locale])) {
            $this->loadCatalogue($locale);
        }

        // Change translation domain to 'messages' if a translation can't be found in the
        // current domain
        if ('messages' !== $domain && false === $this->catalogues[$locale]->has((string) $id, $domain)) {
            $domain = 'messages';
        }

        return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);
    }
623296
public static function create($languageReference, $level = 'info', $objectName = '', $execTime = null)
    {
        if (JsonReader::read(BASE_DIR.'/phiber_config.json')->phiber->log == 1 ? true : false) {
            $date = date('Y-m-d H:i:s');
            switch ($level) {
                case 'info':
                    $levelStr = strtoupper(new Internationalization("log_info"));
                    $msg = "\033[0;35m PHIBER LOG -> [$date] [$levelStr]: (" .
                    new Internationalization("reference") .
                    "=> \"$objectName\") " . new Internationalization($languageReference) .
                    " - ";
                    if($execTime != null){
                        $msg .=  "em " . $execTime . ".";
                    }
                    echo $msg . "\e[0m \n";
                    break;

                case 'warning':
                    $levelStr = strtoupper(new Internationalization("log_warning"));
                    $msg = "\033[1;33m PHIBER LOG -> [$date] [$levelStr]: (" .
                        new Internationalization("reference") .
                        "=> \"$objectName\") " . new Internationalization($languageReference) .
                        " - ";
                    if($execTime != null){
                        $msg .=  "em " . $execTime . ".";
                    }
                    echo $msg . "\e[0m \n";
                    break;

                case 'error':
                    $levelStr = strtoupper(new Internationalization("log_error"));
                    $msg = "\033[0;31m PHIBER LOG -> [$date] [$levelStr]: (" .
                        new Internationalization("reference") .
                        "=> \"$objectName\") " . new Internationalization($languageReference) .
                        " - ";
                    if($execTime != null){
                        $msg .=  "em " . $execTime . ".";
                    }
                    echo $msg . "\e[0m \n";
                    break;
            }
        }
    }
1076412
protected function getTemplateDataForLocale($template,$locale) {
		// path to document with subjects
		$metafile = $this->templatespath.'/'.$locale.'/subjects.xml';
		
		if (!file_exists($metafile)) {
			// file with subjects not found
			return null;
		}
		
		// load and parse document with subjects
		$xml = @file_get_contents($metafile);
		
		if (!$xml || $xml == '') {
			return null;
		}
		
		$array = \LSS\XML2Array::createArray($xml);
		
		// our template is not found in this document so it is not there
		if (!isset($array['templates'][$template])) {
			return null;
		}
		
		$templatefile = $this->templatespath.'/'.$locale.'/'.$template.'.htm';
		
		// check if template file exists for this locale
		if (!file_exists($templatefile)) {
			return null;
		}
		
		$tmpl = ($locale != '') ? $locale.'/':'';
		
		$tmpl .= $template;
		
		// all was fine. return found template
		return array('subject'=>$array['templates'][$template]['subject'],
			'file'=>$tmpl);
	}
490676
public function create($to, $options = array()) {
        $options = new Values($options);

        $data = Values::of(array(
            'To' => $to,
            'From' => $options['from'],
            'MessagingServiceSid' => $options['messagingServiceSid'],
            'Body' => $options['body'],
            'MediaUrl' => Serialize::map($options['mediaUrl'], function($e) { return $e; }),
            'StatusCallback' => $options['statusCallback'],
            'ApplicationSid' => $options['applicationSid'],
            'MaxPrice' => $options['maxPrice'],
            'ProvideFeedback' => Serialize::booleanToString($options['provideFeedback']),
            'ValidityPeriod' => $options['validityPeriod'],
            'ForceDelivery' => Serialize::booleanToString($options['forceDelivery']),
            'SmartEncoded' => Serialize::booleanToString($options['smartEncoded']),
            'InteractiveData' => $options['interactiveData'],
            'ForceOptIn' => Serialize::booleanToString($options['forceOptIn']),
        ));

        $payload = $this->version->create(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new MessageInstance($this->version, $payload, $this->solution['accountSid']);
    }
925316
public static function translateLayout(LayoutInterface $template, $locale, TranslatorInterface $translator = null)
    {
        if (null === $template->getTranslationDomain()) {
            $template = $template->getTranslation($locale);
        } elseif (null !== $translator) {
            static::injectTranslatorValues($translator, $template);
        }

        return $template;
    }