/** * 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; }
/** * @expectedException \Splot\Framework\Resources\Exceptions\ResourceNotFoundException * @covers ::find * @covers ::expand * @covers ::findResource * @covers ::parseResourceName * @covers ::findInApplicationDir * @covers ::findInModuleDir * @covers ::buildResourcePath * @covers ::parseResourceName */ public function testFindingInModuleInvalidModule() { $finder = new Finder($this->application); $finder->findInModuleDir('RandomModule::index.js', 'public/js'); }