Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/ExpiresParsingMiddleware.php

raw symbols SCIP
1 <?php
2 namespace Aws\S3;
3
4 use Aws\CommandInterface;
5 use Aws\ResultInterface;
6 use Psr\Http\Message\RequestInterface;
7
8 /**
9 * Logs a warning when the `expires` header
10 * fails to be parsed.
11 *
12 * @internal
13 */
14 class ExpiresParsingMiddleware
15 {
16 /** @var callable */
17 private $nextHandler;
18
19 /**
20 * Create a middleware wrapper function.
21 *
22 * @return callable
23 */
24 public static function wrap()
25 {
26 return function (callable $handler) {
27 return new self($handler);
28 };
29 }
30
31 /**
32 * @param callable $nextHandler Next handler to invoke.
33 */
34 public function __construct(callable $nextHandler)
35 {
36 $this->nextHandler = $nextHandler;
37 }
38
39 public function __invoke(CommandInterface $command, ?RequestInterface $request = null)
40 {
41 $next = $this->nextHandler;
42 return $next($command, $request)->then(
43 function (ResultInterface $result) {
44 if (empty($result['Expires']) && !empty($result['ExpiresString'])) {
45 trigger_error(
46 "Failed to parse the `expires` header as a timestamp due to "
47 . " an invalid timestamp format.\nPlease refer to `ExpiresString` "
48 . "for the unparsed string format of this header.\n"
49 , E_USER_WARNING
50 );
51 }
52 return $result;
53 }
54 );
55 }
56 }