ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
16
23{
24 protected $mailer;
26
33 public function __construct(\Swift_Mailer $mailer, $message, $level = Logger::ERROR, $bubble = true)
34 {
35 parent::__construct($level, $bubble);
36
37 $this->mailer = $mailer;
38 $this->messageTemplate = $message;
39 }
40
44 protected function send($content, array $records)
45 {
46 $this->mailer->send($this->buildMessage($content, $records));
47 }
48
56 protected function buildMessage($content, array $records)
57 {
58 $message = null;
59 if ($this->messageTemplate instanceof \Swift_Message) {
60 $message = clone $this->messageTemplate;
61 $message->generateId();
62 } elseif (is_callable($this->messageTemplate)) {
63 $message = call_user_func($this->messageTemplate, $content, $records);
64 }
65
66 if (!$message instanceof \Swift_Message) {
67 throw new \InvalidArgumentException('Could not resolve message as instance of Swift_Message or a callable returning it');
68 }
69
70 if ($records) {
71 $subjectFormatter = new LineFormatter($message->getSubject());
72 $message->setSubject($subjectFormatter->format($this->getHighestRecord($records)));
73 }
74
75 $message->setBody($content);
76 $message->setDate(time());
77
78 return $message;
79 }
80
84 public function __get($name)
85 {
86 if ($name === 'message') {
87 trigger_error('SwiftMailerHandler->message is deprecated, use ->buildMessage() instead to retrieve the message', E_USER_DEPRECATED);
88
89 return $this->buildMessage(null, array());
90 }
91
92 throw new \InvalidArgumentException('Invalid property '.$name);
93 }
94}
An exception for terminatinating execution or to throw for unit testing.
Formats incoming records into a one-line string.
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:22