mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 12:17:35 +02:00
Added SwiftMailerHandler, added write to MailHandler
This commit is contained in:
@@ -75,6 +75,23 @@ abstract class MailHandler extends AbstractHandler
|
|||||||
{
|
{
|
||||||
return $this->messageFormat;
|
return $this->messageFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a mail with the given content
|
||||||
|
*
|
||||||
|
* @param string $content
|
||||||
|
*/
|
||||||
|
abstract protected function send($content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function write(array $record)
|
||||||
|
{
|
||||||
|
$content = $record['message'];
|
||||||
|
|
||||||
|
$this->send($content);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a message to send from the given log entry messages
|
* Create a message to send from the given log entry messages
|
||||||
@@ -129,11 +146,4 @@ abstract class MailHandler extends AbstractHandler
|
|||||||
return 'Application logs:\n %records%';
|
return 'Application logs:\n %records%';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a mail with the given message
|
|
||||||
*
|
|
||||||
* @param string $message
|
|
||||||
*/
|
|
||||||
abstract protected function send($message);
|
|
||||||
|
|
||||||
}
|
}
|
47
src/Monolog/Handler/SwiftMailerHandler.php
Normal file
47
src/Monolog/Handler/SwiftMailerHandler.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Monolog package.
|
||||||
|
*
|
||||||
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SwiftMailerHandler uses Swift_Mailer to send the emails
|
||||||
|
*
|
||||||
|
* @author Gyula Sallai
|
||||||
|
*/
|
||||||
|
class SwiftMailerHandler extends MailHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $mailer;
|
||||||
|
protected $message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Swift_Mailer $mailer The mailer to use
|
||||||
|
* @param \Swift_Message $message An example message for real messages,
|
||||||
|
* only the body will be replaced
|
||||||
|
*/
|
||||||
|
public function __construct(\Swift_Mailer $mailer, \Swift_Message $message)
|
||||||
|
{
|
||||||
|
$this->mailer = $mailer;
|
||||||
|
$this->message = $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function send($content)
|
||||||
|
{
|
||||||
|
$message = clone $this->message;
|
||||||
|
$message->setBody($content);
|
||||||
|
|
||||||
|
$this->mailer->send($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Monolog package.
|
||||||
|
*
|
||||||
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@@ -34,9 +43,9 @@ class MailHandlerTest extends TestCase
|
|||||||
|
|
||||||
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
|
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler');
|
||||||
$handler->expects($this->once())
|
$handler->expects($this->once())
|
||||||
->method('write');
|
->method('send');
|
||||||
|
|
||||||
$this->assertTrue($handler->handle($record));
|
$handler->handle($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user