@@ -44,18 +44,28 @@ class OAuth2Api
44
44
private HttpClientInterface $ client ;
45
45
46
46
/**
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
49
50
* @param HttpClientInterface $client The HTTP client to use for making network calls
50
51
* @param Level $level The minimum logging level at which this handler will be triggered
51
52
*/
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
+ ) {
57
58
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
+ }
59
69
}
60
70
61
71
$ this ->client = isset ($ client ) ? $ client : HttpClient::create ();
@@ -178,8 +188,7 @@ public function getAccessToken(
178
188
Environment $ environment ,
179
189
RefreshToken $ refreshToken ,
180
190
array $ scopes
181
- ): OAuthResponse
182
- {
191
+ ): OAuthResponse {
183
192
$ credentials = CredentialUtil::getCredentials ($ environment );
184
193
$ scope = OAuth2Util::buildScopeForRequest ($ scopes );
185
194
0 commit comments