ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
MandrillHandler.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;
15 
22 {
23  protected $message;
24  protected $apiKey;
25 
32  public function __construct($apiKey, $message, $level = Logger::ERROR, $bubble = true)
33  {
34  parent::__construct($level, $bubble);
35 
36  if (!$message instanceof \Swift_Message && is_callable($message)) {
37  $message = call_user_func($message);
38  }
39  if (!$message instanceof \Swift_Message) {
40  throw new \InvalidArgumentException('You must provide either a Swift_Message instance or a callable returning it');
41  }
42  $this->message = $message;
43  $this->apiKey = $apiKey;
44  }
45 
49  protected function send($content, array $records)
50  {
51  $message = clone $this->message;
52  $message->setBody($content);
53  $message->setDate(time());
54 
55  $ch = curl_init();
56 
57  curl_setopt($ch, CURLOPT_URL, 'https://mandrillapp.com/api/1.0/messages/send-raw.json');
58  curl_setopt($ch, CURLOPT_POST, 1);
59  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
60  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
61  'key' => $this->apiKey,
62  'raw_message' => (string) $message,
63  'async' => false,
64  )));
65 
66  Curl\Util::execute($ch);
67  }
68 }
const ERROR
Runtime errors.
Definition: Logger.php:57
__construct($apiKey, $message, $level=Logger::ERROR, $bubble=true)
$records
Definition: simple_test.php:22
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Definition: Util.php:32
Create styles array
The data for the language used.
Base class for all mail handlers.
Definition: MailHandler.php:19
MandrillHandler uses cURL to send the emails to the Mandrill API.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
send($content, array $records)
{}