Skip to content

Commit 470a871

Browse files
committed
refactor: Update credentials classes
- Update `AggregateCredential` class - Delete `HeaderCredential` class - Delete `KeyValueCredential` class - Add `PayloadCredential` class - Delete `QueryCredential` class - Update `TokenAuthCredential` class
1 parent 9d7f1be commit 470a871

6 files changed

Lines changed: 43 additions & 106 deletions

File tree

src/Foundation/Credentials/AggregateCredential.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function applyToOptions(array $options): array
3131
{
3232
return array_reduce(
3333
$this->credentials,
34-
static fn (array $carry, Credential $credential): array => $credential->applyToOptions($carry),
34+
static fn (array $options, Credential $credential): array => $credential->applyToOptions($options),
3535
$options,
3636
);
3737
}

src/Foundation/Credentials/HeaderCredential.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Foundation/Credentials/KeyValueCredential.php

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of the guanguans/notify.
7+
*
8+
* (c) guanguans <ityaozm@gmail.com>
9+
*
10+
* This source file is subject to the MIT license that is bundled.
11+
*/
12+
13+
namespace Guanguans\Notify\Foundation\Credentials;
14+
15+
use GuzzleHttp\RequestOptions;
16+
17+
class PayloadCredential extends NullCredential
18+
{
19+
private array $payload;
20+
21+
private string $type;
22+
23+
public function __construct(array $payload, string $type)
24+
{
25+
$this->payload = $payload;
26+
$this->type = $type;
27+
}
28+
29+
public function applyToOptions(array $options): array
30+
{
31+
$options[$this->type] = array_merge(
32+
$options[$this->type] ?? [],
33+
RequestOptions::MULTIPART === $this->type ? to_multipart($this->payload) : $this->payload
34+
);
35+
36+
return $options;
37+
}
38+
}

src/Foundation/Credentials/QueryCredential.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Foundation/Credentials/TokenAuthCredential.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
namespace Guanguans\Notify\Foundation\Credentials;
1414

15-
class TokenAuthCredential extends HeaderCredential
15+
use GuzzleHttp\RequestOptions;
16+
17+
class TokenAuthCredential extends PayloadCredential
1618
{
1719
public function __construct(string $token, ?string $type = 'Bearer')
1820
{
19-
parent::__construct(trim("$type $token"));
21+
parent::__construct(['Authorization' => trim("$type $token")], RequestOptions::HEADERS);
2022
}
2123
}

0 commit comments

Comments
 (0)