SignatureMiddleware.php 804 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Qcloud\Cos;
  3. use Qcloud\Cos\Exception\ServiceResponseException;
  4. use GuzzleHttp\Promise\PromiseInterface;
  5. use GuzzleHttp\Psr7;
  6. use Psr\Http\Message\RequestInterface;
  7. use Psr\Http\Message\ResponseInterface;
  8. use GuzzleHttp\Exception\RequestException;
  9. class SignatureMiddleware {
  10. private $nextHandler;
  11. protected $signature;
  12. /**
  13. * @param callable $nextHandler Next handler to invoke.
  14. */
  15. public function __construct(callable $nextHandler, $accessKey, $secretKey) {
  16. $this->nextHandler = $nextHandler;
  17. $this->signature = new Signature($accessKey, $secretKey);
  18. }
  19. public function __invoke(RequestInterface $request, array $options) {
  20. $fn = $this->nextHandler;
  21. return $fn($this->signature->signRequest($request), $options);
  22. }
  23. }