ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
12 namespace Monolog\Handler;
13 
14 use Monolog\Logger;
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) {
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 }
const ERROR
Runtime errors.
Definition: Logger.php:57
__get($name)
BC getter, to be removed in 2.0.
$records
Definition: simple_test.php:22
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
__construct(\Swift_Mailer $mailer, $message, $level=Logger::ERROR, $bubble=true)
Create styles array
The data for the language used.
send($content, array $records)
{}
buildMessage($content, array $records)
Creates instance of Swift_Message to be sent.
Base class for all mail handlers.
Definition: MailHandler.php:19
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Formats incoming records into a one-line string.
SwiftMailerHandler uses Swift_Mailer to send the emails.