| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\S3; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\CommandInterface; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\ResultInterface; |
| 7 |
use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface; |
| 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 |
* Create a middleware wrapper function. |
| 20 |
* |
| 21 |
* @return callable |
| 22 |
*/ |
| 23 |
public static function wrap() |
| 24 |
{ |
| 25 |
return function (callable $handler) { |
| 26 |
return new self($handler); |
| 27 |
}; |
| 28 |
} |
| 29 |
/** |
| 30 |
* @param callable $nextHandler Next handler to invoke. |
| 31 |
*/ |
| 32 |
public function __construct(callable $nextHandler) |
| 33 |
{ |
| 34 |
$this->nextHandler = $nextHandler; |
| 35 |
} |
| 36 |
public function __invoke(CommandInterface $command, ?RequestInterface $request = null) |
| 37 |
{ |
| 38 |
$next = $this->nextHandler; |
| 39 |
return $next($command, $request)->then(function (ResultInterface $result) { |
| 40 |
if (empty($result['Expires']) && !empty($result['ExpiresString'])) { |
| 41 |
\trigger_error("Failed to parse the `expires` header as a timestamp due to " . " an invalid timestamp format.\nPlease refer to `ExpiresString` " . "for the unparsed string format of this header.\n", \E_USER_WARNING); |
| 42 |
} |
| 43 |
return $result; |
| 44 |
}); |
| 45 |
} |
| 46 |
} |
| 47 |
|