mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-23 09:36:11 +02:00
Removed Guzzle dependency from Mandrill handler. API calls are now done via cURL
This commit is contained in:
@@ -34,8 +34,7 @@
|
|||||||
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
|
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
|
||||||
"ext-mongo": "Allow sending log messages to a MongoDB server",
|
"ext-mongo": "Allow sending log messages to a MongoDB server",
|
||||||
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
|
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
|
||||||
"rollbar/rollbar": "Allow sending log messages to Rollbar",
|
"rollbar/rollbar": "Allow sending log messages to Rollbar"
|
||||||
"guzzlehttp/guzzle": "Allow sending log messages to Mandrill"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {"Monolog\\": "src/Monolog"}
|
"psr-4": {"Monolog\\": "src/Monolog"}
|
||||||
|
@@ -12,10 +12,9 @@
|
|||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use GuzzleHttp\Client;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MandrillHandler uses GuzzleHttp to send the emails to the Mandrill API
|
* MandrillHandler uses cURL to send the emails to the Mandrill API
|
||||||
*
|
*
|
||||||
* @author Adam Nicholson <adamnicholson10@gmail.com>
|
* @author Adam Nicholson <adamnicholson10@gmail.com>
|
||||||
*/
|
*/
|
||||||
@@ -25,16 +24,15 @@ class MandrillHandler extends MailHandler
|
|||||||
protected $message;
|
protected $message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \GuzzleHttp\Client $client The Guzzle client
|
|
||||||
* @oaram string $apiKey A valid Mandrill API key
|
* @oaram string $apiKey A valid Mandrill API key
|
||||||
* @param callable|\Swift_Message $message An example message for real messages, only the body will be replaced
|
* @param callable|\Swift_Message $message An example message for real messages, only the body will be replaced
|
||||||
* @param integer $level The minimum logging level at which this handler will be triggered
|
* @param integer $level The minimum logging level at which this handler will be triggered
|
||||||
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
||||||
*/
|
*/
|
||||||
public function __construct(Client $client, $apiKey, $message, $level = Logger::ERROR, $bubble = true)
|
public function __construct($apiKey, $message, $level = Logger::ERROR, $bubble = true)
|
||||||
{
|
{
|
||||||
parent::__construct($level, $bubble);
|
parent::__construct($level, $bubble);
|
||||||
$this->client = $client;
|
|
||||||
if (!$message instanceof \Swift_Message && is_callable($message)) {
|
if (!$message instanceof \Swift_Message && is_callable($message)) {
|
||||||
$message = call_user_func($message);
|
$message = call_user_func($message);
|
||||||
}
|
}
|
||||||
@@ -53,12 +51,17 @@ class MandrillHandler extends MailHandler
|
|||||||
$message = clone $this->message;
|
$message = clone $this->message;
|
||||||
$message->setBody($content);
|
$message->setBody($content);
|
||||||
|
|
||||||
$this->client->post('https://mandrillapp.com/api/1.0/messages/send-raw.json', [
|
$ch = curl_init();
|
||||||
'body' => [
|
|
||||||
'key' => $this->apiKey,
|
curl_setopt($ch, CURLOPT_URL, 'https://mandrillapp.com/api/1.0/messages/send-raw.json');
|
||||||
'raw_message' => (string) $message,
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
'async' => false,
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
|
||||||
],
|
'key' => $this->apiKey,
|
||||||
]);
|
'raw_message' => (string) $message,
|
||||||
|
'async' => false,
|
||||||
|
)));
|
||||||
|
|
||||||
|
curl_exec($ch);
|
||||||
|
curl_close ($ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user