diff options
author | Jordi Boggiano <j.boggiano@seld.be> | 2016-11-13 19:57:51 +0100 |
---|---|---|
committer | Jordi Boggiano <j.boggiano@seld.be> | 2016-11-13 19:57:51 +0100 |
commit | d33d11f264d90d517fb8dbca1005f18d4d470440 (patch) | |
tree | 64718dd47a9cb93385768eaa1094c5fbbf4ed573 | |
parent | fe94f2f1adef84bcf338568b3bc733d05ba3c3be (diff) | |
download | monolog-d33d11f264d90d517fb8dbca1005f18d4d470440.zip monolog-d33d11f264d90d517fb8dbca1005f18d4d470440.tar.gz monolog-d33d11f264d90d517fb8dbca1005f18d4d470440.tar.bz2 |
Cache version_compare call, refs #884
-rw-r--r-- | src/Monolog/Formatter/MongoDBFormatter.php | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Monolog/Formatter/MongoDBFormatter.php b/src/Monolog/Formatter/MongoDBFormatter.php index faf37f9..4725c80 100644 --- a/src/Monolog/Formatter/MongoDBFormatter.php +++ b/src/Monolog/Formatter/MongoDBFormatter.php @@ -22,6 +22,7 @@ class MongoDBFormatter implements FormatterInterface { private $exceptionTraceAsString; private $maxNestingLevel; + private $isLegacyMongoExt; /** * @param int $maxNestingLevel 0 means infinite nesting, the $record itself is level 1, $record['context'] is 2 @@ -31,6 +32,8 @@ class MongoDBFormatter implements FormatterInterface { $this->maxNestingLevel = max($maxNestingLevel, 0); $this->exceptionTraceAsString = $exceptionTraceAsString; + + $this->isLegacyMongoExt = version_compare(phpversion('mongodb'), '1.1.9', '<='); } /** @@ -105,19 +108,26 @@ class MongoDBFormatter implements FormatterInterface protected function formatDate(\DateTimeInterface $value, int $nestingLevel): UTCDateTime { - if (version_compare(phpversion('mongodb'), '1.1.9', '<=')) { + if ($this->isLegacyMongoExt) { return $this->legacyGetMongoDbDateTime($value); } return $this->getMongoDbDateTime($value); } - final protected function getMongoDbDateTime(\DateTimeInterface $value): UTCDateTime + private function getMongoDbDateTime(\DateTimeInterface $value): UTCDateTime { return new UTCDateTime((string) floor($value->format('U.u') * 1000)); } - final protected function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTime + /** + * This is needed to support MongoDB Driver v1.19 and below + * + * See https://github.com/mongodb/mongo-php-driver/issues/426 + * + * It can probably be removed in 2.1 or later once MongoDB's 1.2 is released and widely adopted + */ + private function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTime { $milliseconds = floor($value->format('U.u') * 1000); |