| 1 |
<?php |
| 2 |
namespace Aws\S3; |
| 3 |
|
| 4 |
use Aws\CommandInterface; |
| 5 |
use Aws\ResultInterface; |
| 6 |
use Psr\Http\Message\RequestInterface; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class ExpiresParsingMiddleware |
| 15 |
{ |
| 16 |
|
| 17 |
private $nextHandler; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public static function wrap() |
| 25 |
{ |
| 26 |
return function (callable $handler) { |
| 27 |
return new self($handler); |
| 28 |
}; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 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 |
} |