Skip to content

Commit 8848c63

Browse files
author
Castellanos, Eleazar
committed
Changed logic to use CredentialUtil's logger before creating new logger
1 parent cdb582f commit 8848c63

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/main/CredentialUtil.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public static function setLogger(LoggerInterface $logger): void
3636
}
3737
}
3838

39+
public static function getLogger(): ?LoggerInterface
40+
{
41+
return self::$logger;
42+
}
43+
3944
public static function load(string $yamlString): void
4045
{
4146
self::$logger->debug("CredentialHelper.load");

src/main/OAuth2Api.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,28 @@ class OAuth2Api
4444
private HttpClientInterface $client;
4545

4646
/**
47-
* @param resource|string $stream If a missing path can't be created, an
48-
* UnexpectedValueException will be thrown on first write
47+
* @param resource|string $stream If a missing path can't be created and CredentialUtil's
48+
* logger is not set, an UnexpectedValueException will be thrown
49+
* on first write
4950
* @param HttpClientInterface $client The HTTP client to use for making network calls
5051
* @param Level $level The minimum logging level at which this handler will be triggered
5152
*/
52-
public function __construct($stream, ?HttpClientInterface $client = null, ?Level $level = Level::Debug)
53-
{
54-
if (!isset(self::$logger)) {
55-
self::$logger = new Logger('OAuth2Api');
56-
}
53+
public function __construct(
54+
mixed $stream,
55+
?HttpClientInterface $client = null,
56+
?Level $level = Level::Debug
57+
) {
5758
if (!isset(self::$logger)) {
58-
self::$logger->pushHandler(new StreamHandler($stream, $level));
59+
$logger = CredentialUtil::getLogger();
60+
if (isset($logger)) {
61+
self::$logger = $logger;
62+
} else {
63+
self::$logger = new Logger('OAuth2Api');
64+
65+
if (!isset(self::$logger)) {
66+
self::$logger->pushHandler(new StreamHandler($stream, $level));
67+
}
68+
}
5969
}
6070

6171
$this->client = isset($client) ? $client : HttpClient::create();
@@ -178,8 +188,7 @@ public function getAccessToken(
178188
Environment $environment,
179189
RefreshToken $refreshToken,
180190
array $scopes
181-
): OAuthResponse
182-
{
191+
): OAuthResponse {
183192
$credentials = CredentialUtil::getCredentials($environment);
184193
$scope = OAuth2Util::buildScopeForRequest($scopes);
185194

0 commit comments

Comments
 (0)