Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit d4025be

Browse files
committed
🛀 logger fix
1 parent 16d4e03 commit d4025be

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

src/Providers/OAuth2Provider.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Token, Storage\TokenStorageInterface
2020
};
2121
use chillerlan\Traits\ContainerInterface;
22+
use Psr\Log\LoggerInterface;
2223

2324
/**
2425
* from CSRFTokenTrait:
@@ -35,7 +36,7 @@ abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
3536
/**
3637
* @var array
3738
*/
38-
protected $scopes;
39+
protected $scopes = [];
3940

4041
/**
4142
* @var string
@@ -58,12 +59,16 @@ abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
5859
* @param \chillerlan\HTTP\HTTPClientInterface $http
5960
* @param \chillerlan\OAuth\Storage\TokenStorageInterface $storage
6061
* @param \chillerlan\Traits\ContainerInterface $options
62+
* @param \Psr\Log\LoggerInterface|null $logger
6163
* @param array $scopes
6264
*/
63-
public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, array $scopes = null){
64-
parent::__construct($http, $storage, $options);
65+
public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger = null, array $scopes = null){
66+
parent::__construct($http, $storage, $options, $logger);
67+
68+
if($scopes !== null){
69+
$this->scopes = $scopes;
70+
}
6571

66-
$this->scopes = $scopes ?? [];
6772
}
6873

6974
/**

src/Providers/OAuthProvider.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515
use chillerlan\HTTP\{
1616
HTTPClientInterface, HTTPClientTrait
1717
};
18-
use chillerlan\Logger\LogTrait;
1918
use chillerlan\MagicAPI\ApiClientInterface;
2019
use chillerlan\OAuth\Storage\TokenStorageInterface;
2120
use chillerlan\Traits\{
2221
ClassLoader, ContainerInterface, Magic
2322
};
24-
use Psr\Log\LoggerAwareInterface;
23+
use Psr\Log\{
24+
LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger
25+
};
2526
use ReflectionClass;
2627

2728
/**
2829
* @property string $serviceName
2930
* @property string $userRevokeURL
3031
*/
3132
abstract class OAuthProvider implements OAuthInterface, LoggerAwareInterface{
32-
use ClassLoader, Magic, HTTPClientTrait, LogTrait;
33+
use ClassLoader, Magic, HTTPClientTrait, LoggerAwareTrait;
3334

3435
/**
3536
* @var \chillerlan\OAuth\Storage\TokenStorageInterface
@@ -87,12 +88,15 @@ abstract class OAuthProvider implements OAuthInterface, LoggerAwareInterface{
8788
* @param \chillerlan\HTTP\HTTPClientInterface $http
8889
* @param \chillerlan\OAuth\Storage\TokenStorageInterface $storage
8990
* @param \chillerlan\Traits\ContainerInterface $options
91+
* @param \Psr\Log\LoggerInterface|null $logger
9092
*/
91-
public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options){
93+
public function __construct(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger = null){
9294
$this->setHTTPClient($http);
9395

9496
$this->storage = $storage;
9597
$this->options = $options;
98+
$this->logger = $logger ?? new NullLogger;
99+
96100
$this->serviceName = (new ReflectionClass($this))->getShortName();
97101

98102
if($this instanceof ApiClientInterface){

src/Storage/TokenStorageAbstract.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212

1313
namespace chillerlan\OAuth\Storage;
1414

15-
use chillerlan\Logger\LogTrait;
1615
use chillerlan\OAuth\{OAuthOptions, Token};
1716
use chillerlan\Traits\ContainerInterface;
18-
use Psr\Log\LoggerAwareInterface;
17+
use Psr\Log\{
18+
LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger
19+
};
1920

2021
abstract class TokenStorageAbstract implements TokenStorageInterface, LoggerAwareInterface{
21-
use LogTrait;
22+
use LoggerAwareTrait;
2223

2324
protected const TOKEN_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
2425

@@ -31,9 +32,11 @@ abstract class TokenStorageAbstract implements TokenStorageInterface, LoggerAwar
3132
* TokenStorageAbstract constructor.
3233
*
3334
* @param \chillerlan\Traits\ContainerInterface|null $options
35+
* @param \Psr\Log\LoggerInterface|null $logger
3436
*/
35-
public function __construct(ContainerInterface $options = null){
37+
public function __construct(ContainerInterface $options = null, LoggerInterface $logger = null){
3638
$this->options = $options ?? new OAuthOptions;
39+
$this->logger = $logger ?? new NullLogger;
3740
}
3841

3942
/**

tests/API/APITestAbstract.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
HTTPClientAbstract, HTTPClientInterface, HTTPOptionsTrait, HTTPResponseInterface, TinyCurlClient
1717
};
1818
use chillerlan\Logger\{
19-
Log, LogOptions, LogOptionsTrait, Output\LogOutputAbstract
19+
Log, LogOptionsTrait, Output\LogOutputAbstract
2020
};
2121
use chillerlan\OAuth\{
2222
OAuthOptions, Providers\OAuthInterface, Storage\MemoryTokenStorage, Storage\TokenStorageInterface, Token
@@ -102,10 +102,7 @@ protected function setUp(){
102102
$this->storage = new MemoryTokenStorage;
103103
$this->logger = $this->initLogger($this->options);
104104
$this->http = $this->initHttp($this->options);
105-
$this->provider = $this->initProvider($this->http, $this->storage, $this->options);
106-
107-
/** @noinspection PhpUndefinedMethodInspection */
108-
$this->provider->setLogger($this->logger);
105+
$this->provider = $this->initProvider($this->http, $this->storage, $this->options, $this->logger);
109106

110107
$tokenfile = $this->CFGDIR.'/'.$this->provider->serviceName.'.'.$this->TOKEN_EXT;
111108

@@ -160,11 +157,12 @@ protected function __log(string $level, string $message, array $context = null):
160157
* @param \chillerlan\HTTP\HTTPClientInterface $http
161158
* @param \chillerlan\OAuth\Storage\TokenStorageInterface $storage
162159
* @param \chillerlan\Traits\ContainerInterface $options
160+
* @param \Psr\Log\LoggerInterface $logger
163161
*
164162
* @return \chillerlan\OAuth\Providers\OAuthInterface
165163
*/
166-
protected function initProvider(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options){
167-
return new $this->FQCN($http, $storage, $options);
164+
protected function initProvider(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger){
165+
return new $this->FQCN($http, $storage, $options, $logger);
168166
}
169167

170168
/**

tests/API/OAuth2APITestAbstract.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Providers\ClientCredentials, Providers\OAuth2Interface, Storage\TokenStorageInterface, Token
1818
};
1919
use chillerlan\Traits\ContainerInterface;
20+
use Psr\Log\LoggerInterface;
2021

2122
/**
2223
*/
@@ -30,8 +31,8 @@ abstract class OAuth2APITestAbstract extends APITestAbstract{
3031
/**
3132
* @inheritdoc
3233
*/
33-
protected function initProvider(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options){
34-
return new $this->FQCN($http, $storage, $options, $this->scopes);
34+
protected function initProvider(HTTPClientInterface $http, TokenStorageInterface $storage, ContainerInterface $options, LoggerInterface $logger){
35+
return new $this->FQCN($http, $storage, $options, $logger, $this->scopes);
3536
}
3637

3738
public function testOAuth2Instance(){

tests/StorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function initStorage($storageInterface):void{
9090
$db = null;
9191

9292
if($storageInterface === DBTokenStorage::class){
93-
$db = new Database($this->options, null, new NullLogger);
93+
$db = new Database($this->options);
9494

9595
$db->connect();
9696
$db->drop->table($this::TABLE_TOKEN)->query();

0 commit comments

Comments
 (0)