SignatureMiddleware.php 628 B

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