From e9ea22ffeba635474f34b09dc8cbc3e3bb5a1adc Mon Sep 17 00:00:00 2001 From: Mark Garrett Date: Fri, 19 Feb 2016 17:33:40 -0600 Subject: [PATCH] Update to use more generic interfaces PHP 7 can throw Errors and Exceptions, so use `Throwable` interface. `DateTimeInterface` allows for both `DateTime` and `DateTimeImmutable`. --- src/Monolog/Formatter/MongoDBFormatter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Monolog/Formatter/MongoDBFormatter.php b/src/Monolog/Formatter/MongoDBFormatter.php index fb211f17..d40da1f8 100644 --- a/src/Monolog/Formatter/MongoDBFormatter.php +++ b/src/Monolog/Formatter/MongoDBFormatter.php @@ -57,9 +57,9 @@ class MongoDBFormatter implements FormatterInterface { if ($this->maxNestingLevel == 0 || $nestingLevel <= $this->maxNestingLevel) { foreach ($record as $name => $value) { - if ($value instanceof \DateTime) { + if ($value instanceof \DateTimeInterface) { $record[$name] = $this->formatDate($value, $nestingLevel + 1); - } elseif ($value instanceof \Exception) { + } elseif ($value instanceof \Throwable) { $record[$name] = $this->formatException($value, $nestingLevel + 1); } elseif (is_array($value)) { $record[$name] = $this->formatArray($value, $nestingLevel + 1); @@ -82,7 +82,7 @@ class MongoDBFormatter implements FormatterInterface return $this->formatArray($objectVars, $nestingLevel); } - protected function formatException(\Exception $exception, $nestingLevel) + protected function formatException(\Throwable $exception, $nestingLevel) { $formattedException = array( 'class' => get_class($exception), @@ -100,7 +100,7 @@ class MongoDBFormatter implements FormatterInterface return $this->formatArray($formattedException, $nestingLevel); } - protected function formatDate(\DateTime $value, $nestingLevel) + protected function formatDate(\DateTimeInterface $value, $nestingLevel) { $seconds = (int) $value->format('U'); $milliseconds = (int) $value->format('u') / 1000;