Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/ZF-27-MAIL' of https://github.com/Maks3w/zf2 int…
Browse files Browse the repository at this point in the history
…o feature/zen27-mail
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
30 changes: 13 additions & 17 deletions src/Writer/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@

use Zend\Log\Formatter\Simple as SimpleFormatter,
Zend\Log\Exception,
Zend\Mail\Message,
Zend\Mail\Message as MailMessage,
Zend\Mail\Transport,
Zend\Mail\Transport\Exception as MailException,
Zend\Mail\Transport\Sendmail as SendmailTransport;
Zend\Mail\Transport\Exception as TransportException;

/**
* Class used for writing log messages to email via Zend\Mail.
*
* Allows for emailing log messages at and above a certain level via a
* Zend\Mail\Message object. Note that this class only sends the email upon
* completion, so any log entries accumulated are sent in a single email.
* The email is sent using a Zend\Mail\Transport object (Sendmail is default).
* The email is sent using a Zend\Mail\Transport\TransportInterface object
* (Sendmail is default).
*
* @category Zend
* @package Zend_Log
Expand All @@ -55,14 +55,14 @@ class Mail extends AbstractWriter
/**
* Mail message instance to use
*
* @var Message
* @var MailMessage
*/
protected $mail;

/**
* Mail transport instance to use; optional.
*
* @var Transport
* @var Transport\TransportInterface
*/
protected $transport;

Expand All @@ -87,28 +87,28 @@ class Mail extends AbstractWriter
/**
* Constructor
*
* @param Message $mail
* @param Transport $transport
* @param MailMessage $mail
* @param Transport\TransportInterface $transport Optional
*/
public function __construct(Message $mail, Transport $transport = null)
public function __construct(MailMessage $mail, Transport\TransportInterface $transport = null)
{
$this->mail = $mail;
if (null !== $transport) {
$this->setTransport($transport);
} else {
// default transport
$this->setTransport(new SendmailTransport());
$this->setTransport(new Transport\Sendmail());
}
$this->formatter = new SimpleFormatter();
}

/**
* Set the transport message
*
* @param Transport $layout
* @param Transport\TransportInterface $transport
* @return Mail
*/
public function setTransport(Transport $transport)
public function setTransport(Transport\TransportInterface $transport)
{
$this->transport = $transport;
return $this;
Expand All @@ -118,7 +118,6 @@ public function setTransport(Transport $transport)
* Places event line into array of lines to be used as message body.
*
* @param array $event Event data
* @return void
*/
protected function doWrite(array $event)
{
Expand All @@ -144,7 +143,6 @@ protected function doWrite(array $event)
*
* @param string $subject Subject prepend text
* @return Mail
* @throws Exception\RuntimeException
*/
public function setSubjectPrependText($subject)
{
Expand All @@ -155,8 +153,6 @@ public function setSubjectPrependText($subject)
/**
* Sends mail to recipient(s) if log entries are present. Note that both
* plaintext and HTML portions of email are handled here.
*
* @return void
*/
public function shutdown()
{
Expand All @@ -181,7 +177,7 @@ public function shutdown()
// stack frame.
try {
$this->transport->send($this->mail);
} catch (MailException $e) {
} catch (TransportException\ExceptionInterface $e) {
trigger_error(
"unable to send log entries via email; " .
"message = {$e->getMessage()}; " .
Expand Down
13 changes: 6 additions & 7 deletions test/Writer/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
use Zend\Log\Logger,
Zend\Log\Writer\Mail as MailWriter,
Zend\Log\Formatter\Simple as SimpleFormatter,
Zend\Mail\Message,
Zend\Mail\Transport\File as FileTransport,
Zend\Mail\Transport\FileOptions;
Zend\Mail\Message as MailMessage,
Zend\Mail\Transport;

/**
* @category Zend
Expand All @@ -50,11 +49,11 @@ class MailTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$message = new Message();
$transport = new FileTransport();
$options = new FileOptions(array(
$message = new MailMessage();
$transport = new Transport\File();
$options = new Transport\FileOptions(array(
'path' => __DIR__,
'callback' => function (FileTransport $transport) {
'callback' => function (Transport\File $transport) {
return MailTest::FILENAME;
},
));
Expand Down

0 comments on commit 8fefc9f

Please sign in to comment.