scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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  
16 /**
17 * MandrillHandler uses cURL to send the emails to the Mandrill API
18 *
19 * @author Adam Nicholson <adamnicholson10@gmail.com>
20 */
21 class MandrillHandler extends MailHandler
22 {
23 protected $message;
24 protected $apiKey;
25  
26 /**
27 * @param string $apiKey A valid Mandrill API key
28 * @param callable|\Swift_Message $message An example message for real messages, only the body will be replaced
29 * @param int $level The minimum logging level at which this handler will be triggered
30 * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
31 */
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  
46 /**
47 * {@inheritdoc}
48 */
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 }