Ejemplo n.º 1
0
 protected function provideMessage()
 {
     $message = new Message();
     $message->setSubject('Test');
     $message->setBody('Test');
     return $message;
 }
Ejemplo n.º 2
0
 /**
  * Composes an email message from the definition by the given name.
  * 
  * @param string $name Name of the message to compose. Must be usable by Splot Framework Resources Finder
  *                     and not contain the final file extensions.
  * @param array $variables [optional] Variables for replacement in the templates.
  * @return Message
  */
 public function composeMessage($name, array $variables = array())
 {
     $templates = array('subject' => null, 'html' => null, 'text' => null);
     foreach ($templates as $type => $path) {
         try {
             $templates[$type] = $this->resourceFinder->find($name . '.' . $type . '.twig', 'email');
         } catch (ResourceNotFoundException $e) {
         }
         // ignore
     }
     if ($templates['subject'] === null) {
         throw new MailNotFoundException('Could not find "' . $name . '.subject.twig" file to determine mail subject.', 404);
     }
     if ($templates['html'] === null && $templates['text'] === null) {
         throw new MailNotFoundException('Could not find neither html nor text templates for mail "' . $name . '".');
     }
     $message = Message::newInstance();
     $message->setSubject($this->twig->render($templates['subject'], $variables));
     if ($templates['html'] !== null) {
         $message->setBody($this->twig->render($templates['html'], $variables), 'text/html');
         if ($templates['text']) {
             $message->addPart($this->twig->render($templates['text'], $variables), 'text/plain');
         }
     } else {
         $message->setBody($this->twig->render($templates['text'], $variables), 'text/plain');
     }
     return $message;
 }