Substitute templated variables into the given message and subject

@param string $message
@param string $subject
@param array $substitutions
@return array Resulting array(subject, message)
187121
public function injectMessageReplacements($message, $subject, $substitutions) {
		// Handle empty messages
		if(empty($subject) && empty($message)) return array(null, null);

		// Check if there's a role specific message
		$subjectText = str_replace(
			array_keys($substitutions),
			array_values($substitutions),
			$subject ?: $message
		);
		$messageText = str_replace(
			array_keys($substitutions),
			array_values($substitutions),
			$message ?: $subject
		);
		return array($subjectText, $messageText);
	}
866442
private function replace(
        ColumnMetadata $columnMetadata,
        string $searchTerm,
        string $replaceTerm,
        string $subject
    ): FieldReplaceResult {
        $fieldReplaced = null;
        foreach ($this->replacementStrategyList as $replacementStrategy) {
            if ($replacementStrategy->canReplace($searchTerm, $subject)) {
                $fieldReplaced = $replacementStrategy->replace(
                    $columnMetadata,
                    $searchTerm,
                    $replaceTerm,
                    $subject
                );
                break;
            }
        }

        if (is_null($fieldReplaced)) {
            throw new \RuntimeException('Error trying to replace "' . $searchTerm . '" with "' . $replaceTerm . '"');
        }

        return $fieldReplaced;
    }
89162
public static function replaceLast($search, $replace, $subject)
    {
        $position = mb_strrpos($subject, $search);

        if ($position !== false) {
            return mb_substr($subject, 0, $position).$replace.mb_substr($subject, $position + mb_strlen($search));
        }

        return $subject;
    }
1030103
public static function replace($pattern, $replacement, $subject, $limit = -1): ReplaceResult
    {
        return ReplaceResult::for($pattern, $replacement, $subject, $limit);
    }
42967
public function replacePlaceholders($message, $values = array())
    {
        $length = count($values);
        $i = 1;
        foreach ($values as $value) {
            if (is_array($value)) {
                $message = preg_replace_callback('/%' . $i . '\{(.*?)\}\{(.*?)\}/', function ($matches) use ($value) {
                    $length = count($value);
                    $list = '';
                    for ($i = 0; $i < $length; $i ++) {
                        $list .= $value[$i];
                        if ($i != ($length - 1)) {
                            if ($i == ($length - 2)) {
                                $list .= $matches[2];
                            } else {
                                $list .= $matches[1];
                            }
                        }
                    }
                    return $list;
                }, $message);
            } else {
                $message = str_replace('%' . $i, $value, $message);
            }
            $i ++;
        }
        return $message;
    }
549427
protected function call($eventName, $subject = null, $message = null)
    {
        if (!isset($this->events[$eventName])) {
            return $subject;
        }

        foreach ($this->events[$eventName] as $listener) {
            if ($this->stop) {
                break;
            }

            $subject = $listener($this->container, $subject, $message, $eventName);
        }

        return $subject;
    }
602258
public function createMessage(Message $message, Subject $subject)
    {
    	$forum = $subject->getCategory()->getForum();
        $collection = new ResourceCollection(array($forum->getResourceNode()));

        if (!$this->sc->isGranted('post', $collection)) {
            throw new AccessDeniedHttpException($collection->getErrorsForDisplay());
        }

     	$user = $this->sc->getToken()->getUser();
        $message->setCreator($user);
        $message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
        $message->setSubject($subject);
        $this->om->persist($message);
        $this->om->flush();
		$this->dispatch(new CreateMessageEvent($message));
        $this->sendMessageNotification($message, $message->getCreator());

        return $message;
    }
519083
public function createMessage($subject = null, $body = null, $contentType = null, $charset = null)
    {
        $message = Swift_Message::newInstance($subject, $body, $contentType, $charset);

        if(null !== $this->fromEmail) {
            
            if(null === $this->fromName) {
                $message->setFrom($this->fromEmail);
            } else {
                $message->setFrom($this->fromEmail, $this->fromName);
            }
            
        }

        return $message;
    }
768965
public static function eliminateDupilcates($subject, $eliminate = "\\")
    {
        $pattern = $eliminate . $eliminate;

        while (strpos($subject, $pattern) !== false) {
            $subject = str_replace($pattern, $eliminate, $subject);
        }

        return $subject;
    }
1141501
protected function interpolate($message, array $placeholders = [])
    {
        if ($placeholders) {
            $replace = [];
            foreach ($placeholders as $key => $val) {
                $replace['{' . $key . '}'] = $val;
            }

            return strtr($message, $replace);
        } else {
            return $message;
        }
    }
1344110
public static function send(string $to, string $subject, string $view, array $viewVars = [], $builder = null, $from = 'default')
    {
        $message = static::createMessage($to, $subject, $from);
        if (is_callable($builder)) {
            $builder($message);
        }
        $message->setBody(static::view($view, $viewVars));

        self::getMailer()->send($message);
    }
308770
private function messageFromTemplate(array $message, $template, array $templateVars)
    {
        if (!isset($message['html'])) {
            $htmlTemplate = 'emails/'.$template;
            $htmlView = new View($htmlTemplate, $templateVars);
            $message['html'] = $htmlView->render();
        }

        if (!isset($message['text'])) {
            $textTemplate = 'emails/text/'.$template;
            $textView = new View($textTemplate, $templateVars);
            $message['text'] = $textView->render();
        }

        return $message;
    }
1230949
protected function replaceTemplate($search, $replace, &$subject)
    {
        $subject = $this->strReplace($search, $replace, $subject);

        return $this;
    }
1271084
public function _preg_filter($subject, $pattern, $replacement = '', $limit = -1)
    {
        if (!isset($subject)) {
            return;
        } else {
            return preg_filter($pattern, $replacement, $subject, $limit);
        }
    }
996243
public function send($to, $subject, $message, $options)
    {
        if (!is_array($options)) {
            $options = array('from' => (string) $options);
        }

        settype($to, 'array');

        $result = null;
        $this->hook->attach('mail.send', $to, $subject, $message, $options, $result);

        if (isset($result)) {
            return $result;
        }

        return $this->mail($to, $subject, $message, $options);
    }
1263877
public function createDefaultMessage( $test, $vars )
	{
		$substitutions = array();

		// Look for variables in the test
		foreach ( $vars as $name => $var )
		{
			if ( strpos( $test, "\$$name") === false ) continue;

			$substitutions[ $name ]	= Resource::valueToString( $var );
		}

		foreach ( $substitutions as $name => $substitution )
		{
			$test = preg_replace('/\b' . $name . '\b/', "$name $substitution", $test);
			// $test = str_replace( $name, $name . " " . $substitution, $test );
		}

		return $test;
	}
168563
public function message($to = '', $subject = '', $body = '')
    {
        $message = $this->transport->newMessage();

        if ($to) {
            $message->to($to);
        }
        if ($subject) {
            $message->subject($subject);
        }
        if ($body) {
            $message->body($body);
        }

        $message->setMailer($this);

        return $message;
    }