/** * @see \BoilerAppMessenger\Message\MessageRendererInterface::renderMessageBody() * @param \BoilerAppMessenger\Message\Message $oMessage * @return string */ public function renderMessageBody(\BoilerAppMessenger\Message\Message $oMessage) { //Build layout $this->initLayout(); //Retrieve layout $oLayout = $this->layout(); //Set subject to layout $oLayout->subject = $oMessage->getSubject(); //Set content to layout $oLayout->content = $this->render($oMessage->getBody()); //Manage assets if service is available if ($this->hasAssetsBundleService()) { $this->getAssetsBundleService()->getOptions()->setModuleName(current(explode('\\', __NAMESPACE__)))->setControllerName(self::MEDIA)->setRenderer($this); $this->getAssetsBundleService()->renderAssets(); } //Render children layout if needed if ($oLayout->hasChildren()) { $this->renderChildren($oLayout); } //Render layout $sBody = $this->render($oLayout); //Inline style if service is available if ($this->hasStyleInlinerService()) { $sBody = $this->getStyleInlinerService()->processHtml($sBody); } return $sBody; }
/** * @see \BoilerAppMessenger\Message\MessageTransporterInterface::sendMessage() * @param \BoilerAppMessenger\Message\Message $oMessage * @throws \UnexpectedValueException * @return \BoilerAppMessenger\Media\Mail\MailMessageTransporter */ public function sendMessage(\BoilerAppMessenger\Message\Message $oMessage) { //Adapt message $oAdaptedMessage = new \Zend\Mail\Message(); $oAdaptedMessage->setEncoding('UTF-8'); //From Sender $oFrom = $oMessage->getFrom(); if ($oFrom instanceof \BoilerAppMessenger\Media\Mail\MailMessageUserInterface) { $oAdaptedMessage->setFrom($oFrom->getUserEmail(), $oFrom->getUserDisplayName()); } else { throw new \UnexpectedValueException(sprintf('"From" sender expects an instance of \\BoilerAppMessenger\\Mail\\MailMessageUserInterface, "%s" given', is_scalar($oFrom) ? $oFrom : (is_object($oFrom) ? get_class($oFrom) : gettype($oFrom)))); } //To Recipiants foreach ($oMessage->getTo() as $oTo) { if ($oTo instanceof \BoilerAppMessenger\Media\Mail\MailMessageUserInterface) { $oAdaptedMessage->addTo($oTo->getUserEmail(), $oTo->getUserDisplayName()); } else { throw new \UnexpectedValueException(sprintf('"To" Recipiant expects an instance of \\BoilerAppMessenger\\Mail\\MailMessageUserInterface, "%s" given', is_scalar($oTo) ? $oTo : (is_object($oTo) ? get_class($oTo) : gettype($oTo)))); } } //Subject $oAdaptedMessage->setSubject($oMessage->getSubject()); //Reset attachments $this->attachments = array(); foreach ($oMessage->getAttachments() as $sAttachmentFilePath) { $this->addFileAttachment($sAttachmentFilePath); } //Body $oBodyPart = new \Zend\Mime\Part(preg_replace_callback('/src="([^"]+)"/', array($this, 'processImageSrc'), $this->getMessageRenderer()->renderMessageBody($oMessage))); $oBodyPart->type = \Zend\Mime\Mime::TYPE_HTML; $oBody = new \Zend\Mime\Message(); $oBody->setParts(array_merge(array($oBodyPart), $this->attachments)); $oAdaptedMessage->setBody($oBody)->setEncoding('UTF-8'); //Send message $this->getMailTransporter()->send($oAdaptedMessage); return $this; }