-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1926
- Loading branch information
Showing
12 changed files
with
83 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,38 +11,13 @@ | |
|
||
namespace Monolog; | ||
|
||
use DateTimeZone; | ||
class_alias(JsonSerializableDateTimeImmutable::class, 'Monolog\DateTimeImmutable'); | ||
|
||
/** | ||
* Overrides default json encoding of date time objects | ||
* | ||
* @author Menno Holtkamp | ||
* @author Jordi Boggiano <[email protected]> | ||
*/ | ||
class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable | ||
{ | ||
private bool $useMicroseconds; | ||
|
||
public function __construct(bool $useMicroseconds, ?DateTimeZone $timezone = null) | ||
{ | ||
$this->useMicroseconds = $useMicroseconds; | ||
|
||
// if you like to use a custom time to pass to Logger::addRecord directly, | ||
// call modify() or setTimestamp() on this instance to change the date after creating it | ||
parent::__construct('now', $timezone); | ||
} | ||
|
||
public function jsonSerialize(): string | ||
{ | ||
if ($this->useMicroseconds) { | ||
return $this->format('Y-m-d\TH:i:s.uP'); | ||
} | ||
|
||
return $this->format('Y-m-d\TH:i:sP'); | ||
} | ||
|
||
public function __toString(): string | ||
if (false) { | ||
Check failure on line 16 in src/Monolog/DateTimeImmutable.php GitHub Actions / PHPStan (8.1)
|
||
/** | ||
* @deprecated Use \Monolog\JsonSerializableDateTimeImmutable instead. | ||
*/ | ||
class DateTimeImmutable extends JsonSerializableDateTimeImmutable | ||
{ | ||
return $this->jsonSerialize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Monolog; | ||
|
||
use DateTimeZone; | ||
|
||
/** | ||
* Overrides default json encoding of date time objects | ||
* | ||
* @author Menno Holtkamp | ||
* @author Jordi Boggiano <[email protected]> | ||
*/ | ||
class JsonSerializableDateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable | ||
{ | ||
private bool $useMicroseconds; | ||
|
||
public function __construct(bool $useMicroseconds, ?DateTimeZone $timezone = null) | ||
{ | ||
$this->useMicroseconds = $useMicroseconds; | ||
|
||
// if you like to use a custom time to pass to Logger::addRecord directly, | ||
// call modify() or setTimestamp() on this instance to change the date after creating it | ||
parent::__construct('now', $timezone); | ||
} | ||
|
||
public function jsonSerialize(): string | ||
{ | ||
if ($this->useMicroseconds) { | ||
return $this->format('Y-m-d\TH:i:s.uP'); | ||
} | ||
|
||
return $this->format('Y-m-d\TH:i:sP'); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->jsonSerialize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters