Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility Office 365 HTML emails #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
return array(
);
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class TransportOptionsFactory implements FactoryInterface {

public function createService(ServiceLocatorInterface $serviceLocator) {
class TransportOptionsFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');

return new TransportOptions(isset($config['goaliomailservice']) ? $config['goaliomailservice'] : array());
}

}
}
24 changes: 15 additions & 9 deletions src/GoalioMailService/Mail/Options/TransportOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Zend\Stdlib\AbstractOptions;

class TransportOptions extends AbstractOptions {

class TransportOptions extends AbstractOptions
{
/** @var string */
protected $transportClass = 'Zend\Mail\Transport\File';

Expand All @@ -22,7 +22,8 @@ class TransportOptions extends AbstractOptions {
*
* @return $this
*/
public function setTransportOptions($transportOptions) {
public function setTransportOptions($transportOptions)
{
$this->transportOptions = $transportOptions;

return $this;
Expand All @@ -31,7 +32,8 @@ public function setTransportOptions($transportOptions) {
/**
* @return array
*/
public function getTransportOptions() {
public function getTransportOptions()
{
return $this->transportOptions;
}

Expand All @@ -40,7 +42,8 @@ public function getTransportOptions() {
*
* @return $this
*/
public function setOptionsClass($optionsClass) {
public function setOptionsClass($optionsClass)
{
$this->optionsClass = $optionsClass;

return $this;
Expand All @@ -49,7 +52,8 @@ public function setOptionsClass($optionsClass) {
/**
* @return string
*/
public function getOptionsClass() {
public function getOptionsClass()
{
return $this->optionsClass;
}

Expand All @@ -58,7 +62,8 @@ public function getOptionsClass() {
*
* @return $this
*/
public function setTransportClass($transportClass) {
public function setTransportClass($transportClass)
{
$this->transportClass = $transportClass;

return $this;
Expand All @@ -67,8 +72,9 @@ public function setTransportClass($transportClass) {
/**
* @return string
*/
public function getTransportClass() {
public function getTransportClass()
{
return $this->transportClass;
}

}
}
90 changes: 52 additions & 38 deletions src/GoalioMailService/Mail/Service/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part as MimePart;

class Message implements ServiceManagerAwareInterface {

class Message implements ServiceManagerAwareInterface
{
/**
*
* @var ServiceManager
Expand All @@ -17,19 +17,22 @@ class Message implements ServiceManagerAwareInterface {

/**
*
* @param ServiceManager $serviceManager
* @param ServiceManager $serviceManager
* @return AbstractService
*/
public function setServiceManager(ServiceManager $serviceManager) {
public function setServiceManager(ServiceManager $serviceManager)
{
$this->serviceManager = $serviceManager;

return $this;
}

/**
*
* @return ServiceManager
*/
public function getServiceManager() {
public function getServiceManager()
{
return $this->serviceManager;
}

Expand All @@ -48,19 +51,20 @@ public function getServiceManager() {
/**
* Return a HTML message ready to be sent
*
* @param array|string $from
* A string containing the sender e-mail address, or if array with keys email and name
* @param array|string $to
* An array containing the recipients of the mail
* @param string $subject
* Subject of the mail
* @param string|\Zend\View\Model\ModelInterface $nameOrModel
* Either the template to use, or a ViewModel
* @param null|array $values
* Values to use when the template is rendered
* @param array|string $from
* A string containing the sender e-mail address, or if array with keys email and name
* @param array|string $to
* An array containing the recipients of the mail
* @param string $subject
* Subject of the mail
* @param string|\Zend\View\Model\ModelInterface $nameOrModel
* Either the template to use, or a ViewModel
* @param null|array $values
* Values to use when the template is rendered
* @return Message
*/
public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values = array()) {
public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values = array())
{
$renderer = $this->getRenderer();
$content = $renderer->render($nameOrModel, $values);

Expand All @@ -73,25 +77,29 @@ public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values =
$body = new MimeMessage();
$body->setParts(array($text, $html));

return $this->getDefaultMessage($from, 'utf-8', $to, $subject, $body);
$message = $this->getDefaultMessage($from, 'utf-8', $to, $subject, $body);
$message->getHeaders()->get('content-type')->setType(\Zend\Mime\Mime::MULTIPART_ALTERNATIVE);

return $message;
}

/**
* Return a text message ready to be sent
*
* @param array|string $from
* A string containing the sender e-mail address, or if array with keys email and name
* @param array|string $to
* An array containing the recipients of the mail
* @param string $subject
* Subject of the mail
* @param string|\Zend\View\Model\ModelInterface $nameOrModel
* Either the template to use, or a ViewModel
* @param null|array $values
* Values to use when the template is rendered
* @param array|string $from
* A string containing the sender e-mail address, or if array with keys email and name
* @param array|string $to
* An array containing the recipients of the mail
* @param string $subject
* Subject of the mail
* @param string|\Zend\View\Model\ModelInterface $nameOrModel
* Either the template to use, or a ViewModel
* @param null|array $values
* Values to use when the template is rendered
* @return Message
*/
public function createTextMessage($from, $to, $subject, $nameOrModel, $values = array()) {
public function createTextMessage($from, $to, $subject, $nameOrModel, $values = array())
{
$renderer = $this->getRenderer();
$content = $renderer->render($nameOrModel, $values);

Expand All @@ -103,7 +111,8 @@ public function createTextMessage($from, $to, $subject, $nameOrModel, $values =
*
* @param MailMessage $message
*/
public function send(MailMessage $message) {
public function send(MailMessage $message)
{
$this->getTransport()
->send($message);
}
Expand All @@ -113,8 +122,9 @@ public function send(MailMessage $message) {
*
* @return \Zend\View\Renderer\RendererInterface
*/
public function getRenderer() {
if($this->renderer === null) {
public function getRenderer()
{
if ($this->renderer === null) {
$serviceManager = $this->getServiceManager();
$this->renderer = $serviceManager->get('goaliomailservice_renderer');
}
Expand All @@ -127,7 +137,8 @@ public function getRenderer() {
*
* @return $this
*/
public function setRenderer($renderer) {
public function setRenderer($renderer)
{
$this->renderer = $renderer;

return $this;
Expand All @@ -138,8 +149,9 @@ public function setRenderer($renderer) {
*
* @return \Zend\Mail\Transport\TransportInterface
*/
public function getTransport() {
if($this->transport === null) {
public function getTransport()
{
if ($this->transport === null) {
$this->transport = $this->getServiceManager()
->get('goaliomailservice_transport');
}
Expand All @@ -152,7 +164,8 @@ public function getTransport() {
*
* @return $this
*/
public function setTransport($transport) {
public function setTransport($transport)
{
$this->transport = $transport;

return $this;
Expand All @@ -167,8 +180,9 @@ public function setTransport($transport) {
*
* @return MailMessage
*/
protected function getDefaultMessage($from, $encoding, $to, $subject, $body) {
if(is_string($from)) {
protected function getDefaultMessage($from, $encoding, $to, $subject, $body)
{
if (is_string($from)) {
$from = array('email' => $from, 'name' => $from);
}

Expand All @@ -181,4 +195,4 @@ protected function getDefaultMessage($from, $encoding, $to, $subject, $body) {

return $message;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface;

class TransportFactory implements FactoryInterface {

public function createService(ServiceLocatorInterface $serviceLocator) {

class TransportFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var TransportOptions $options */
$options = $serviceLocator->get('goaliomailservice_options');

if(!class_exists($options->getTransportClass())) {
if (!class_exists($options->getTransportClass())) {
throw new \Exception('Transport class has to be configured');
}

Expand All @@ -22,7 +22,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) {
/** @var TransportInterface $transport */
$transport = new $transportClass;

if(class_exists($options->getOptionsClass())) {
if (class_exists($options->getOptionsClass())) {
$transportOptionsClass = $options->getOptionsClass();
$transportOptions = new $transportOptionsClass;
$transportOptions->setFromArray($options->getTransportOptions());
Expand All @@ -31,4 +31,4 @@ public function createService(ServiceLocatorInterface $serviceLocator) {

return $transport;
}
}
}
8 changes: 4 additions & 4 deletions src/GoalioMailService/Mail/View/MailPhpRendererFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Renderer\PhpRenderer;

class MailPhpRendererFactory implements FactoryInterface {

class MailPhpRendererFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$renderer = new PhpRenderer();
Expand All @@ -21,7 +21,7 @@ public function createService(ServiceLocatorInterface $serviceLocator)
$application = $serviceLocator->get('Application');
$event = $application->getMvcEvent();

if($event !== null) {
if ($event !== null) {
$model = $serviceLocator->get('Application')->getMvcEvent()->getViewModel();

$modelHelper = $renderer->plugin('view_model');
Expand All @@ -30,4 +30,4 @@ public function createService(ServiceLocatorInterface $serviceLocator)

return $renderer;
}
}
}
15 changes: 8 additions & 7 deletions src/GoalioMailService/Module.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace GoalioMailService;

use Zend\Mvc\MvcEvent;
use Zend\Loader\StandardAutoloader;
use Zend\Loader\AutoloaderFactory;

class Module {

public function getAutoloaderConfig() {
class Module
{
public function getAutoloaderConfig()
{
return array(
AutoloaderFactory::STANDARD_AUTOLOADER => array(
StandardAutoloader::LOAD_NS => array(
Expand All @@ -17,11 +17,13 @@ public function getAutoloaderConfig() {
);
}

public function getConfig() {
public function getConfig()
{
return include __DIR__ . '/../../config/module.config.php';
}

public function getServiceConfig() {
public function getServiceConfig()
{
return array(
'shared' => array(
'goaliomailservice_message' => false
Expand All @@ -37,4 +39,3 @@ public function getServiceConfig() {
);
}
}

Loading