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

Commit fb8117b

Browse files
committed
:octocat:
1 parent 9e397da commit fb8117b

File tree

7 files changed

+20
-54
lines changed

7 files changed

+20
-54
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
"require": {
2323
"php": "^7.2",
2424
"ext-json":"*",
25-
"chillerlan/php-traits": "^2.0",
25+
"chillerlan/php-dotenv": "^1.0",
26+
"chillerlan/php-settings-container": "^1.0",
2627
"chillerlan/php-httpinterface": "dev-master",
2728
"psr/log": "^1.0"
2829
},
2930
"require-dev": {
30-
"chillerlan/php-log": "^2.0",
31+
"chillerlan/php-log": "^3.0",
3132
"phpunit/phpunit": "^7.3"
3233
},
3334
"autoload": {

examples/oauth-example-common.php

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @license MIT
88
*/
99

10-
use chillerlan\HTTP\{CurlClient, HTTPClientAbstract, HTTPResponseInterface};
10+
use chillerlan\HTTP\CurlClient;
1111
use chillerlan\Logger\{Log, LogOptionsTrait, Output\ConsoleLog};
1212
use chillerlan\OAuth\{OAuthOptions, Storage\SessionStorage};
13-
use chillerlan\Traits\{DotEnv, ImmutableSettingsInterface};
13+
use chillerlan\DotEnv\DotEnv;
1414

1515
ini_set('date.timezone', 'Europe/Amsterdam');
1616

@@ -32,54 +32,21 @@
3232

3333
// log
3434
'minLogLevel' => 'debug',
35-
36-
// test http client
37-
'sleep' => 0.25,
3835
];
3936

40-
/** @var \chillerlan\Traits\ImmutableSettingsInterface $options */
37+
/** @var \chillerlan\Settings\SettingsContainerInterface $options */
4138
$options = new class($options_arr) extends OAuthOptions{
4239
use LogOptionsTrait;
4340

4441
protected $sleep;
4542
};
4643

4744
$logger = new Log;
48-
$logger->addInstance(new ConsoleLog($options), 'console');
45+
$logger->addInstance(new ConsoleLog, 'console');
4946

5047
/** @var \chillerlan\HTTP\HTTPClientInterface $http */
51-
$http = new class($options) extends HTTPClientAbstract{
52-
53-
protected $client;
54-
55-
public function __construct(ImmutableSettingsInterface $options){
56-
parent::__construct($options);
57-
$this->client = new CurlClient($this->options);
58-
}
59-
60-
protected function getResponse():HTTPResponseInterface{
61-
62-
$this->logger->debug('$args', [
63-
'$url' => $this->requestURL,
64-
'$params' => $this->requestParams,
65-
'$method' => $this->requestMethod,
66-
'$body' => $this->requestBody,
67-
'$headers' => $this->requestHeaders,
68-
]);
69-
70-
$response = $this->client->request($this->requestURL, $this->requestParams, $this->requestMethod, $this->requestBody, $this->requestHeaders);
71-
72-
$this->logger->debug($response->body, (array)$response->headers);
73-
74-
usleep($this->options->sleep * 1000000);
75-
76-
return $response;
77-
}
78-
79-
};
80-
81-
#$http->setLogger($logger);
48+
$http = new CurlClient($options);
8249

8350
/** @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage */
84-
$storage = new SessionStorage($options);
51+
$storage = new SessionStorage;
8552
#$storage->setLogger($logger);

src/Core/OAuthProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function request(string $path, array $params = null, string $method = nul
273273
$request = $this->getRequestAuthorization($request, $token);
274274

275275
if(is_array($body) && $request->hasHeader('content-type')){
276-
$contentType = strtolower($request->getHeader('content-type'));
276+
$contentType = strtolower($request->getHeaderLine('content-type'));
277277

278278
if($contentType === 'application/x-www-form-urlencoded'){
279279
$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));

src/Storage/OAuthStorageAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace chillerlan\OAuth\Storage;
1414

1515
use chillerlan\OAuth\{Core\AccessToken, OAuthOptions};
16-
use chillerlan\Traits\ImmutableSettingsInterface;
16+
use chillerlan\Settings\SettingsContainerInterface;
1717
use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
1818

1919
abstract class OAuthStorageAbstract implements OAuthStorageInterface, LoggerAwareInterface{
@@ -27,10 +27,10 @@ abstract class OAuthStorageAbstract implements OAuthStorageInterface, LoggerAwar
2727
/**
2828
* OAuthStorageAbstract constructor.
2929
*
30-
* @param \chillerlan\Traits\ImmutableSettingsInterface|null $options
30+
* @param \chillerlan\Settings\SettingsContainerInterface|null $options
3131
* @param \Psr\Log\LoggerInterface|null $logger
3232
*/
33-
public function __construct(ImmutableSettingsInterface $options = null, LoggerInterface $logger = null){
33+
public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){
3434
$this->options = $options ?? new OAuthOptions;
3535
$this->logger = $logger ?? new NullLogger;
3636
}

src/Storage/SessionStorage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace chillerlan\OAuth\Storage;
1414

1515
use chillerlan\OAuth\Core\AccessToken;
16-
use chillerlan\Traits\ImmutableSettingsInterface;
16+
use chillerlan\Settings\SettingsContainerInterface;
1717

1818
class SessionStorage extends OAuthStorageAbstract{
1919

@@ -35,9 +35,9 @@ class SessionStorage extends OAuthStorageAbstract{
3535
/**
3636
* Session constructor.
3737
*
38-
* @param \chillerlan\Traits\ImmutableSettingsInterface|null $options
38+
* @param \chillerlan\Settings\SettingsContainerInterface|null $options
3939
*/
40-
public function __construct(ImmutableSettingsInterface $options = null){
40+
public function __construct(SettingsContainerInterface $options = null){
4141
parent::__construct($options);
4242

4343
$this->sessionVar = $this->options->sessionTokenVar;

tests/OAuthTestAbstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use chillerlan\Logger\Log;
1616
use chillerlan\Logger\LogOptions;
1717
use chillerlan\Logger\Output\LogOutputAbstract;
18-
use chillerlan\Traits\DotEnv;
18+
use chillerlan\DotEnv\DotEnv;
1919
use PHPUnit\Framework\TestCase;
2020

2121
abstract class OAuthTestAbstract extends TestCase{
@@ -43,7 +43,7 @@ abstract class OAuthTestAbstract extends TestCase{
4343
protected $options;
4444

4545
/**
46-
* @var \chillerlan\Traits\DotEnv
46+
* @var \chillerlan\DotEnv\DotEnv
4747
*/
4848
protected $env;
4949

tests/Storage/StorageTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
namespace chillerlan\OAuthTest\Storage;
1414

1515
use chillerlan\OAuth\Core\AccessToken;
16-
use chillerlan\OAuth\Storage\{MemoryStorage, OAuthStorageInterface, SessionStorage};
16+
use chillerlan\OAuth\Storage\{MemoryStorage, SessionStorage};
1717
use chillerlan\OAuthTest\OAuthTestAbstract;
18-
use chillerlan\Traits\ClassLoader;
1918

2019
class StorageTest extends OAuthTestAbstract{
21-
use ClassLoader;
2220

2321
protected const STORAGE_INTERFACES = [
2422
'MemoryStorage' => [MemoryStorage::class],
@@ -42,7 +40,7 @@ protected function setUp(){
4240
}
4341

4442
protected function initStorage($storageInterface):void{
45-
$this->storage = $this->loadClass($storageInterface, OAuthStorageInterface::class);
43+
$this->storage = new $storageInterface;
4644
}
4745

4846
/**

0 commit comments

Comments
 (0)