ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\SwiftMailerHandler Class Reference

SwiftMailerHandler uses Swift_Mailer to send the emails. More...

+ Inheritance diagram for Monolog\Handler\SwiftMailerHandler:
+ Collaboration diagram for Monolog\Handler\SwiftMailerHandler:

Public Member Functions

 __construct (\Swift_Mailer $mailer, $message, $level=Logger::ERROR, $bubble=true)
 
 __get ($name)
 BC getter, to be removed in 2.0. More...
 
- Public Member Functions inherited from Monolog\Handler\MailHandler
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
bool true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
bool
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 
 reset ()
 

Protected Member Functions

 send ($content, array $records)
 {} More...
 
 getSubjectFormatter ($format)
 Gets the formatter for the Swift_Message subject. More...
 
 buildMessage ($content, array $records)
 Creates instance of Swift_Message to be sent. More...
 
- Protected Member Functions inherited from Monolog\Handler\MailHandler
 send ($content, array $records)
 Send a mail with the given content. More...
 
 write (array $record)
 {} More...
 
 getHighestRecord (array $records)
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $mailer
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Private Attributes

 $messageTemplate
 

Detailed Description

SwiftMailerHandler uses Swift_Mailer to send the emails.

Author
Gyula Sallai

Definition at line 24 of file SwiftMailerHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\SwiftMailerHandler::__construct ( \Swift_Mailer  $mailer,
  $message,
  $level = Logger::ERROR,
  $bubble = true 
)
Parameters
\Swift_Mailer$mailerThe mailer to use
callable | \Swift_Message$messageAn example message for real messages, only the body will be replaced
int$levelThe minimum logging level at which this handler will be triggered
bool$bubbleWhether the messages that are handled can bubble up the stack or not

Definition at line 35 of file SwiftMailerHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\SwiftMailerHandler\$mailer, and $message.

36  {
37  parent::__construct($level, $bubble);
38 
39  $this->mailer = $mailer;
40  $this->messageTemplate = $message;
41  }
catch(Exception $e) $message

Member Function Documentation

◆ __get()

Monolog\Handler\SwiftMailerHandler::__get (   $name)

BC getter, to be removed in 2.0.

Definition at line 101 of file SwiftMailerHandler.php.

References $name, and Monolog\Handler\SwiftMailerHandler\buildMessage().

102  {
103  if ($name === 'message') {
104  trigger_error('SwiftMailerHandler->message is deprecated, use ->buildMessage() instead to retrieve the message', E_USER_DEPRECATED);
105 
106  return $this->buildMessage(null, array());
107  }
108 
109  throw new \InvalidArgumentException('Invalid property '.$name);
110  }
buildMessage($content, array $records)
Creates instance of Swift_Message to be sent.
+ Here is the call graph for this function:

◆ buildMessage()

Monolog\Handler\SwiftMailerHandler::buildMessage (   $content,
array  $records 
)
protected

Creates instance of Swift_Message to be sent.

Parameters
string$contentformatted email body to be sent
array$recordsLog records that formed the content
Returns

Definition at line 69 of file SwiftMailerHandler.php.

References $message, Monolog\Handler\SwiftMailerHandler\$messageTemplate, and Monolog\Handler\SwiftMailerHandler\getSubjectFormatter().

Referenced by Monolog\Handler\SwiftMailerHandler\__get(), and Monolog\Handler\SwiftMailerHandler\send().

70  {
71  $message = null;
72  if ($this->messageTemplate instanceof \Swift_Message) {
74  $message->generateId();
75  } elseif (is_callable($this->messageTemplate)) {
76  $message = call_user_func($this->messageTemplate, $content, $records);
77  }
78 
79  if (!$message instanceof \Swift_Message) {
80  throw new \InvalidArgumentException('Could not resolve message as instance of Swift_Message or a callable returning it');
81  }
82 
83  if ($records) {
84  $subjectFormatter = $this->getSubjectFormatter($message->getSubject());
85  $message->setSubject($subjectFormatter->format($this->getHighestRecord($records)));
86  }
87 
88  $message->setBody($content);
89  if (version_compare(Swift::VERSION, '6.0.0', '>=')) {
90  $message->setDate(new \DateTimeImmutable());
91  } else {
92  $message->setDate(time());
93  }
94 
95  return $message;
96  }
$records
Definition: simple_test.php:22
catch(Exception $e) $message
getSubjectFormatter($format)
Gets the formatter for the Swift_Message subject.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSubjectFormatter()

Monolog\Handler\SwiftMailerHandler::getSubjectFormatter (   $format)
protected

Gets the formatter for the Swift_Message subject.

Parameters
string$formatThe format of the subject
Returns
FormatterInterface

Definition at line 57 of file SwiftMailerHandler.php.

References $format.

Referenced by Monolog\Handler\SwiftMailerHandler\buildMessage().

58  {
59  return new LineFormatter($format);
60  }
$format
Definition: metadata.php:141
+ Here is the caller graph for this function:

◆ send()

Monolog\Handler\SwiftMailerHandler::send (   $content,
array  $records 
)
protected

{}

Definition at line 46 of file SwiftMailerHandler.php.

References Monolog\Handler\SwiftMailerHandler\buildMessage().

47  {
48  $this->mailer->send($this->buildMessage($content, $records));
49  }
$records
Definition: simple_test.php:22
buildMessage($content, array $records)
Creates instance of Swift_Message to be sent.
+ Here is the call graph for this function:

Field Documentation

◆ $mailer

Monolog\Handler\SwiftMailerHandler::$mailer
protected

◆ $messageTemplate

Monolog\Handler\SwiftMailerHandler::$messageTemplate
private

The documentation for this class was generated from the following file: