From 1b769912d1d7f1c6ed8b17de7a9aee9ba3fe92b0 Mon Sep 17 00:00:00 2001 From: Brant Messenger Date: Sun, 18 Jun 2017 18:16:17 -0500 Subject: [PATCH 01/10] =?UTF-8?q?PHP=20Versions=20less=20than=205.3.6=20th?= =?UTF-8?q?rows=20undefined=20constant=20DEBUG=5FBACKTRAC=E2=80=A6=20(#986?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PHP Versions less than 5.3.6 throws undefined constant DEBUG_BACKTRACE_IGNORE_ARGS Notice: Use of undefined constant DEBUG_BACKTRACE_IGNORE_ARGS - assumed 'DEBUG_BACKTRACE_IGNORE_ARGS' in /vendor/monolog/monolog/src/Monolog/Processor/IntrospectionProcessor.php on line 58 * Define DEBUG_BACKTRACE_IGNORE_ARGS if not defined. * Solution using PHP_VERSION_ID and not defining... ...DEBUG_BACKTRACE_IGNORE_ARGS --- src/Monolog/Processor/IntrospectionProcessor.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index 2691630a..2c07caed 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -55,7 +55,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); From deb0ea4ee79a389b3004b0ef43499def511bbe9d Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Mon, 19 Jun 2017 01:33:57 +0200 Subject: [PATCH 02/10] Use first day/first month for date calculations in RotatingFileHandlerTest (#963) When making the calculations for the filename of the current month using date('d') does not work because you may run into the situation where you run the tests on a day in a month that does not exist in the previous month, for example March 30th. As there is no February 30th, PHP will skip ahead to March, and the filename for the "previous" month will incorrectly be "2017-03" instead of the expected "2017-02". Using the first day of the month instead of the current day of the month solves this problem. For consistency we now also use the first month of each year for calculations regarding years even if this is not necessary, it would break symmetry if we don't, plus it makes it clear that the value is not relevant in the calculation. --- tests/Monolog/Handler/RotatingFileHandlerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index c5106175..f1feb228 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -111,10 +111,10 @@ class RotatingFileHandlerTest extends TestCase return $now + 86400 * $ago; }; $monthCallback = function($ago) { - return gmmktime(0, 0, 0, date('n') + $ago, date('d'), date('Y')); + return gmmktime(0, 0, 0, date('n') + $ago, 1, date('Y')); }; $yearCallback = function($ago) { - return gmmktime(0, 0, 0, date('n'), date('d'), date('Y') + $ago); + return gmmktime(0, 0, 0, 1, 1, date('Y') + $ago); }; return array( From 765d225554770c45ee01267151769bab40bab91c Mon Sep 17 00:00:00 2001 From: Douglas Reith Date: Mon, 19 Jun 2017 09:47:42 +1000 Subject: [PATCH 03/10] Support HeadlessChrome (#966) * Support HeadlessChrome --- src/Monolog/Handler/ChromePHPHandler.php | 2 +- tests/Monolog/Handler/ChromePHPHandlerTest.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/ChromePHPHandler.php b/src/Monolog/Handler/ChromePHPHandler.php index b00fa844..785cb0c9 100644 --- a/src/Monolog/Handler/ChromePHPHandler.php +++ b/src/Monolog/Handler/ChromePHPHandler.php @@ -36,7 +36,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; diff --git a/tests/Monolog/Handler/ChromePHPHandlerTest.php b/tests/Monolog/Handler/ChromePHPHandlerTest.php index ef3cd1cb..0449f8b1 100644 --- a/tests/Monolog/Handler/ChromePHPHandlerTest.php +++ b/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(); From 357ae23fa4e13c0154575298a39b08627f1a97a8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 19 Jun 2017 01:07:32 +0200 Subject: [PATCH 04/10] Tweak HandlerWrapper example in docblock, fixes #991 --- src/Monolog/Handler/HandlerWrapper.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Monolog/Handler/HandlerWrapper.php b/src/Monolog/Handler/HandlerWrapper.php index 56bc2704..e540d80f 100644 --- a/src/Monolog/Handler/HandlerWrapper.php +++ b/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 */ From 6fdf686a023c28e1ccf554224feebc8b56b24ca2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 19 Jun 2017 01:27:33 +0200 Subject: [PATCH 05/10] Use Aws\Sdk instead of Aws\Common\Aws, fixes #969, fixes #977 --- src/Monolog/Handler/DynamoDbHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/DynamoDbHandler.php b/src/Monolog/Handler/DynamoDbHandler.php index ad1011d3..237b71f6 100644 --- a/src/Monolog/Handler/DynamoDbHandler.php +++ b/src/Monolog/Handler/DynamoDbHandler.php @@ -11,7 +11,7 @@ namespace Monolog\Handler; -use Aws\Common\Aws; +use Aws\Sdk; use Aws\DynamoDb\DynamoDbClient; use Aws\DynamoDb\Marshaler; use Monolog\Formatter\ScalarFormatter; @@ -55,7 +55,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 { From d84af8db3ca6d4432d95b1abb9f0542f1a17f4cb Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Wed, 31 May 2017 21:40:53 +0200 Subject: [PATCH 06/10] Fix SwiftMailerHandler support for Swiftmailer 6.0+ --- composer.json | 2 +- src/Monolog/Handler/SwiftMailerHandler.php | 7 ++++++- tests/Monolog/Handler/SwiftMailerHandlerTest.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f74b7b97..3b0c8805 100644 --- a/composer.json +++ b/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", "phpunit/phpunit-mock-objects": "2.3.0", "jakub-onderka/php-parallel-lint": "0.9" diff --git a/src/Monolog/Handler/SwiftMailerHandler.php b/src/Monolog/Handler/SwiftMailerHandler.php index aba13967..72f44a53 100644 --- a/src/Monolog/Handler/SwiftMailerHandler.php +++ b/src/Monolog/Handler/SwiftMailerHandler.php @@ -13,6 +13,7 @@ namespace Monolog\Handler; use Monolog\Logger; use Monolog\Formatter\LineFormatter; +use Swift; /** * SwiftMailerHandler uses Swift_Mailer to send the emails @@ -73,7 +74,11 @@ class SwiftMailerHandler extends MailHandler } $message->setBody($content); - $message->setDate(time()); + if (version_compare(Swift::VERSION, '6.0.0', '>=')) { + $message->setDate(new \DateTimeImmutable()); + } else { + $message->setDate(time()); + } return $message; } diff --git a/tests/Monolog/Handler/SwiftMailerHandlerTest.php b/tests/Monolog/Handler/SwiftMailerHandlerTest.php index 85886910..1d62940f 100644 --- a/tests/Monolog/Handler/SwiftMailerHandlerTest.php +++ b/tests/Monolog/Handler/SwiftMailerHandlerTest.php @@ -98,7 +98,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'); From 2ea3d95ca22e6feb89a77da30b94781ece723c00 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 19 Jun 2017 00:42:25 +0200 Subject: [PATCH 07/10] Make sure this works on any hostname --- tests/Monolog/Formatter/GelfMessageFormatterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index 889dc542..4a247616 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -226,7 +226,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase public function testFormatWithUnlimitedLength() { - $formatter = new GelfMessageFormatter(null, null, 'ctxt_', PHP_INT_MAX); + $formatter = new GelfMessageFormatter('LONG_SYSTEM_NAME', null, 'ctxt_', PHP_INT_MAX); $record = array( 'level' => Logger::ERROR, 'level_name' => 'ERROR', From 188a46836b70ed65c2080e828230eff1c5d1b118 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 19 Jun 2017 02:06:55 +0200 Subject: [PATCH 08/10] Fix DyanmoDbHandler test suite --- tests/Monolog/Handler/DynamoDbHandlerTest.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Monolog/Handler/DynamoDbHandlerTest.php b/tests/Monolog/Handler/DynamoDbHandlerTest.php index f3a69680..2e6c348d 100644 --- a/tests/Monolog/Handler/DynamoDbHandlerTest.php +++ b/tests/Monolog/Handler/DynamoDbHandlerTest.php @@ -52,13 +52,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)); @@ -67,7 +74,7 @@ class DynamoDbHandlerTest extends TestCase ->method('__call') ->with('putItem', array(array( 'TableName' => 'foo', - 'Item' => $formatted, + 'Item' => $expFormatted, ))); $handler->handle($record); From 52d9096b14a500dc7629e620deddfa6a14b091b6 Mon Sep 17 00:00:00 2001 From: Harm Bandstra Date: Mon, 27 Mar 2017 16:32:27 +0200 Subject: [PATCH 09/10] Explicitly set content-type header, and post JSON as body --- src/Monolog/Handler/SlackWebhookHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/SlackWebhookHandler.php b/src/Monolog/Handler/SlackWebhookHandler.php index 0d3e3ea1..c890d93e 100644 --- a/src/Monolog/Handler/SlackWebhookHandler.php +++ b/src/Monolog/Handler/SlackWebhookHandler.php @@ -87,7 +87,8 @@ class SlackWebhookHandler extends AbstractProcessingHandler if (defined('CURLOPT_SAFE_UPLOAD')) { curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); } - curl_setopt($ch, CURLOPT_POSTFIELDS, array('payload' => $postString)); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-type: application/json']); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); Curl\Util::execute($ch); } From 4260b467605950f2de533b43dab15b92324acd2b Mon Sep 17 00:00:00 2001 From: Harm Bandstra Date: Mon, 27 Mar 2017 16:57:59 +0200 Subject: [PATCH 10/10] SlackWebhookHandler: refactor curl_setopt to curl_setopt_array --- src/Monolog/Handler/SlackWebhookHandler.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Monolog/Handler/SlackWebhookHandler.php b/src/Monolog/Handler/SlackWebhookHandler.php index c890d93e..64f88eaa 100644 --- a/src/Monolog/Handler/SlackWebhookHandler.php +++ b/src/Monolog/Handler/SlackWebhookHandler.php @@ -81,14 +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_HTTPHEADER, ['Content-type: application/json']); - curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); + + curl_setopt_array($ch, $options); Curl\Util::execute($ch); }