Jordi Boggiano 8 лет назад
Родитель
Сommit
1417e2d183

+ 1 - 1
composer.json

@@ -24,7 +24,7 @@
         "doctrine/couchdb": "~1.0@dev",
         "aws/aws-sdk-php": "^2.4.9 || ^3.0",
         "php-amqplib/php-amqplib": "~2.4",
-        "swiftmailer/swiftmailer": "~5.3",
+        "swiftmailer/swiftmailer": "^5.3|^6.0",
         "php-console/php-console": "^3.1.3",
         "jakub-onderka/php-parallel-lint": "^0.9",
         "predis/predis": "^1.1",

+ 1 - 1
src/Monolog/Handler/ChromePHPHandler.php

@@ -37,7 +37,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
     /**
      * Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)
      */
-    const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
+    const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
 
     protected static $initialized = false;
 

+ 2 - 2
src/Monolog/Handler/DynamoDbHandler.php

@@ -11,7 +11,7 @@
 
 namespace Monolog\Handler;
 
-use Aws\Common\Aws;
+use Aws\Sdk;
 use Aws\DynamoDb\DynamoDbClient;
 use Monolog\Formatter\FormatterInterface;
 use Aws\DynamoDb\Marshaler;
@@ -56,7 +56,7 @@ class DynamoDbHandler extends AbstractProcessingHandler
      */
     public function __construct(DynamoDbClient $client, $table, $level = Logger::DEBUG, $bubble = true)
     {
-        if (defined('Aws\Common\Aws::VERSION') && version_compare(Aws::VERSION, '3.0', '>=')) {
+        if (defined('Aws\Sdk::VERSION') && version_compare(Sdk::VERSION, '3.0', '>=')) {
             $this->version = 3;
             $this->marshaler = new Marshaler;
         } else {

+ 10 - 8
src/Monolog/Handler/HandlerWrapper.php

@@ -16,15 +16,17 @@ use Monolog\Formatter\FormatterInterface;
 /**
  * This simple wrapper class can be used to extend handlers functionality.
  *
- * Example: A filtering handle. Inherit from this class, override isHandling() like this
+ * Example: A custom filtering that can be applied to any handler.
  *
- * public function isHandling(array $record)
- * {
- *      if ($record meets certain conditions) {
- *          return false;
- *      }
- *      return $this->handler->isHandling($record);
- * }
+ * Inherit from this class and override handle() like this:
+ *
+ *   public function handle(array $record)
+ *   {
+ *        if ($record meets certain conditions) {
+ *            return false;
+ *        }
+ *        return $this->handler->handle($record);
+ *   }
  *
  * @author Alexey Karapetov <alexey@karapetov.com>
  */

+ 10 - 5
src/Monolog/Handler/SlackWebhookHandler.php

@@ -81,13 +81,18 @@ class SlackWebhookHandler extends AbstractProcessingHandler
         $postString = json_encode($postData);
 
         $ch = curl_init();
-        curl_setopt($ch, CURLOPT_URL, $this->webhookUrl);
-        curl_setopt($ch, CURLOPT_POST, true);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $options = [
+            CURLOPT_URL => $this->webhookUrl,
+            CURLOPT_POST => true,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_HTTPHEADER => ['Content-type: application/json'],
+            CURLOPT_POSTFIELDS => $postString
+        ];
         if (defined('CURLOPT_SAFE_UPLOAD')) {
-            curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
+            $options[CURLOPT_SAFE_UPLOAD] = true;
         }
-        curl_setopt($ch, CURLOPT_POSTFIELDS, array('payload' => $postString));
+
+        curl_setopt_array($ch, $options);
 
         Curl\Util::execute($ch);
     }

+ 6 - 1
src/Monolog/Handler/SwiftMailerHandler.php

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
 use Monolog\Logger;
 use Monolog\Formatter\LineFormatter;
 use Swift_Message;
+use Swift;
 
 /**
  * SwiftMailerHandler uses Swift_Mailer to send the emails
@@ -79,7 +80,11 @@ class SwiftMailerHandler extends MailHandler
         }
 
         $message->setBody($content, $mime);
-        $message->setDate(time());
+        if (version_compare(Swift::VERSION, '6.0.0', '>=')) {
+            $message->setDate(new \DateTimeImmutable());
+        } else {
+            $message->setDate(time());
+        }
 
         return $message;
     }

+ 6 - 1
src/Monolog/Processor/IntrospectionProcessor.php

@@ -51,7 +51,12 @@ class IntrospectionProcessor
             return $record;
         }
 
-        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+        /*
+        * http://php.net/manual/en/function.debug-backtrace.php
+        * As of 5.3.6, DEBUG_BACKTRACE_IGNORE_ARGS option was added.
+        * Any version less than 5.3.6 must use the DEBUG_BACKTRACE_IGNORE_ARGS constant value '2'.
+        */
+        $trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
 
         // skip first since it's always the current method
         array_shift($trace);

+ 16 - 1
tests/Monolog/Handler/ChromePHPHandlerTest.php

@@ -25,8 +25,13 @@ class ChromePHPHandlerTest extends TestCase
         $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0';
     }
 
-    public function testHeaders()
+    /**
+     * @dataProvider agentsProvider
+     */
+    public function testHeaders($agent)
     {
+        $_SERVER['HTTP_USER_AGENT'] = $agent;
+
         $handler = new TestChromePHPHandler();
         $handler->setFormatter($this->getIdentityFormatter());
         $handler->handle($this->getRecord(Logger::DEBUG));
@@ -47,6 +52,16 @@ class ChromePHPHandlerTest extends TestCase
         $this->assertEquals($expected, $handler->getHeaders());
     }
 
+    public static function agentsProvider()
+    {
+        return array(
+            array('Monolog Test; Chrome/1.0'),
+            array('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'),
+            array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/56.0.2924.76 Chrome/56.0.2924.76 Safari/537.36'),
+            array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36'),
+        );
+    }
+
     public function testHeadersOverflow()
     {
         $handler = new TestChromePHPHandler();

+ 9 - 2
tests/Monolog/Handler/DynamoDbHandlerTest.php

@@ -53,13 +53,20 @@ class DynamoDbHandlerTest extends TestCase
         $handler = new DynamoDbHandler($this->client, 'foo');
         $handler->setFormatter($formatter);
 
+        $isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
+        if ($isV3) {
+            $expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2));
+        } else {
+            $expFormatted = $formatted;
+        }
+
         $formatter
              ->expects($this->once())
              ->method('format')
              ->with($record)
              ->will($this->returnValue($formatted));
         $this->client
-             ->expects($this->once())
+             ->expects($isV3 ? $this->never() : $this->once())
              ->method('formatAttributes')
              ->with($this->isType('array'))
              ->will($this->returnValue($formatted));
@@ -68,7 +75,7 @@ class DynamoDbHandlerTest extends TestCase
              ->method('__call')
              ->with('putItem', [[
                  'TableName' => 'foo',
-                 'Item' => $formatted,
+                 'Item' => $expFormatted,
              ]]);
 
         $handler->handle($record);

+ 4 - 4
tests/Monolog/Handler/RotatingFileHandlerTest.php

@@ -102,11 +102,11 @@ class RotatingFileHandlerTest extends TestCase
         $dayCallback = function ($ago) use ($now) {
             return $now + 86400 * $ago;
         };
-        $monthCallback = function ($ago) {
-            return gmmktime(0, 0, 0, (int) (date('n') + $ago), (int) date('d'), (int) date('Y'));
+        $monthCallback = function($ago) {
+            return gmmktime(0, 0, 0, (int) (date('n') + $ago), 1, (int) date('Y'));
         };
-        $yearCallback = function ($ago) {
-            return gmmktime(0, 0, 0, (int) date('n'), (int) date('d'), (int) (date('Y') + $ago));
+        $yearCallback = function($ago) {
+            return gmmktime(0, 0, 0, 1, 1, (int) (date('Y') + $ago));
         };
 
         return [

+ 1 - 1
tests/Monolog/Handler/SwiftMailerHandlerTest.php

@@ -99,7 +99,7 @@ class SwiftMailerHandlerTest extends TestCase
 
     public function testMessageHaveUniqueId()
     {
-        $messageTemplate = \Swift_Message::newInstance();
+        $messageTemplate = new \Swift_Message();
         $handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
 
         $method = new \ReflectionMethod('Monolog\Handler\SwiftMailerHandler', 'buildMessage');