generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d5e29c
commit 2459c38
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vanthao03596\GhtkSdk\HttpClient\Plugin; | ||
|
||
use Http\Client\Common\Plugin; | ||
use Http\Promise\Promise; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
final class ReferToken implements Plugin | ||
{ | ||
/** | ||
* The authorization token. | ||
* | ||
* @var string | ||
*/ | ||
private $token; | ||
|
||
/** | ||
* Create a new authentication plugin instance. | ||
* | ||
* @param string $token | ||
* @return void | ||
*/ | ||
public function __construct(string $token) | ||
{ | ||
$this->token = $token; | ||
} | ||
|
||
/** | ||
* @return Promise | ||
*/ | ||
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise | ||
{ | ||
$request = $request->withHeader('X-Refer-Token', $this->token); | ||
|
||
return $next($request); | ||
} | ||
} |