ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SwiftMailerHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
15
22{
23 protected $mailer;
25
32 public function __construct(\Swift_Mailer $mailer, $message, $level = Logger::ERROR, $bubble = true)
33 {
34 parent::__construct($level, $bubble);
35
36 $this->mailer = $mailer;
37 $this->messageTemplate = $message;
38 }
39
43 protected function send($content, array $records)
44 {
45 $this->mailer->send($this->buildMessage($content, $records));
46 }
47
55 protected function buildMessage($content, array $records)
56 {
57 $message = null;
58 if ($this->messageTemplate instanceof \Swift_Message) {
59 $message = clone $this->messageTemplate;
60 } else if (is_callable($this->messageTemplate)) {
61 $message = call_user_func($this->messageTemplate, $content, $records);
62 }
63
64 if (!$message instanceof \Swift_Message) {
65 throw new \InvalidArgumentException('Could not resolve message as instance of Swift_Message or a callable returning it');
66 }
67
68 $message->setBody($content);
69 $message->setDate(time());
70
71 return $message;
72 }
73
77 public function __get($name)
78 {
79 if ($name === 'message') {
80 trigger_error('SwiftMailerHandler->message is deprecated, use ->buildMessage() instead to retrieve the message', E_USER_DEPRECATED);
81
82 return $this->buildMessage(null, array());
83 }
84
85 throw new \InvalidArgumentException('Invalid property '.$name);
86 }
87}
Base class for all mail handlers.
Definition: MailHandler.php:20
SwiftMailerHandler uses Swift_Mailer to send the emails.
send($content, array $records)
{Send a mail with the given content.}
__construct(\Swift_Mailer $mailer, $message, $level=Logger::ERROR, $bubble=true)
__get($name)
BC getter, to be removed in 2.0.
buildMessage($content, array $records)
Creates instance of Swift_Message to be sent.
Monolog log channel.
Definition: Logger.php:28
const ERROR
Runtime errors.
Definition: Logger.php:57
$records
Definition: simple_test.php:17