| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | /** @var string */ |
| 24 | 24 | private $presignParam; |
| 25 | 25 | /** @var bool */ |
| 26 | 26 | private $requireDifferentRegion; |
| 27 | - public function __construct(array $options, callable $endpointProvider, AwsClientInterface $client, callable $nextHandler) | |
| 27 | + public function __construct(array $options, $endpointProvider, AwsClientInterface $client, callable $nextHandler) | |
| 28 | 28 | { |
| 29 | 29 | $this->endpointProvider = $endpointProvider; |
| 30 | 30 | $this->client = $client; |
| 31 | 31 | $this->nextHandler = $nextHandler; |
| @@ -34,9 +34,9 @@ | ||
| 34 | 34 | $this->presignParam = !empty($options['presign_param']) ? $options['presign_param'] : 'PresignedUrl'; |
| 35 | 35 | $this->extraQueryParams = !empty($options['extra_query_params']) ? $options['extra_query_params'] : []; |
| 36 | 36 | $this->requireDifferentRegion = !empty($options['require_different_region']); |
| 37 | 37 | } |
| 38 | - public static function wrap(AwsClientInterface $client, callable $endpointProvider, array $options = []) | |
| 38 | + public static function wrap(AwsClientInterface $client, $endpointProvider, array $options = []) | |
| 39 | 39 | { |
| 40 | 40 | return function (callable $handler) use($endpointProvider, $client, $options) { |
| 41 | 41 | $f = new PresignUrlMiddleware($options, $endpointProvider, $client, $handler); |
| 42 | 42 | return $f; |
| @@ -41,11 +41,11 @@ | ||
| 41 | 41 | $f = new PresignUrlMiddleware($options, $endpointProvider, $client, $handler); |
| 42 | 42 | return $f; |
| 43 | 43 | }; |
| 44 | 44 | } |
| 45 | - public function __invoke(CommandInterface $cmd, RequestInterface $request = null) | |
| 45 | + public function __invoke(CommandInterface $cmd, ?RequestInterface $request = null) | |
| 46 | 46 | { |
| 47 | - if (\in_array($cmd->getName(), $this->commandPool) && !isset($cmd->{'__skip' . $cmd->getName()})) { | |
| 47 | + if (\in_array($cmd->getName(), $this->commandPool) && !isset($cmd['__skip' . $cmd->getName()])) { | |
| 48 | 48 | $cmd['DestinationRegion'] = $this->client->getRegion(); |
| 49 | 49 | if (!empty($cmd['SourceRegion']) && !empty($cmd[$this->presignParam])) { |
| 50 | 50 | goto nexthandler; |
| 51 | 51 | } |
| @@ -61,13 +61,18 @@ | ||
| 61 | 61 | { |
| 62 | 62 | $cmdName = $cmd->getName(); |
| 63 | 63 | $newCmd = $client->getCommand($cmdName, $cmd->toArray()); |
| 64 | 64 | // Avoid infinite recursion by flagging the new command. |
| 65 | - $newCmd->{'__skip' . $cmdName} = \true; | |
| 65 | + $newCmd['__skip' . $cmdName] = \true; | |
| 66 | 66 | // Serialize a request for the operation. |
| 67 | 67 | $request = \Dudlewebs\WPMCS\s3\Aws\serialize($newCmd); |
| 68 | 68 | // Create the new endpoint for the target endpoint. |
| 69 | - $endpoint = EndpointProvider::resolve($this->endpointProvider, ['region' => $cmd['SourceRegion'], 'service' => $this->serviceName])['endpoint']; | |
| 69 | + if ($this->endpointProvider instanceof \Dudlewebs\WPMCS\s3\Aws\EndpointV2\EndpointProviderV2) { | |
| 70 | + $providerArgs = \array_merge($this->client->getEndpointProviderArgs(), ['Region' => $cmd['SourceRegion']]); | |
| 71 | + $endpoint = $this->endpointProvider->resolveEndpoint($providerArgs)->getUrl(); | |
| 72 | + } else { | |
| 73 | + $endpoint = EndpointProvider::resolve($this->endpointProvider, ['region' => $cmd['SourceRegion'], 'service' => $this->serviceName])['endpoint']; | |
| 74 | + } | |
| 70 | 75 | // Set the request to hit the target endpoint. |
| 71 | 76 | $uri = $request->getUri()->withHost((new Uri($endpoint))->getHost()); |
| 72 | 77 | $request = $request->withUri($uri); |
| 73 | 78 | // Create a presigned URL for our generated request. |
| @@ -76,9 +81,9 @@ | ||
| 76 | 81 | $paramsToAdd = \false; |
| 77 | 82 | if (!empty($this->extraQueryParams[$cmdName])) { |
| 78 | 83 | foreach ($this->extraQueryParams[$cmdName] as $param) { |
| 79 | 84 | if (!\strpos($currentQueryParams, $param)) { |
| 80 | - $paramsToAdd = "&{$param}={$cmd[$param]}"; | |
| 85 | + $paramsToAdd = "&{$param}=" . \urlencode($cmd[$param]); | |
| 81 | 86 | } |
| 82 | 87 | } |
| 83 | 88 | } |
| 84 | 89 | return (string) $signer->presign(SignatureV4::convertPostToGet($request, $paramsToAdd ?: ""), $client->getCredentials()->wait(), '+1 hour')->getUri(); |