PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / S3 / GetBucketLocationParser.php

GetBucketLocationParser.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/S3/GetBucketLocationParser.php

41 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\S3;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Parser\AbstractParser;
6 use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape;
7 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
9 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
10 /**
11 * @internal Decorates a parser for the S3 service to correctly handle the
12 * GetBucketLocation operation.
13 */
14 class GetBucketLocationParser extends AbstractParser
15 {
16 /**
17 * @param callable $parser Parser to wrap.
18 */
19 public function __construct(callable $parser)
20 {
21 $this->parser = $parser;
22 }
23 public function __invoke(CommandInterface $command, ResponseInterface $response)
24 {
25 $fn = $this->parser;
26 $result = $fn($command, $response);
27 if ($command->getName() === 'GetBucketLocation') {
28 $location = 'us-east-1';
29 if (\preg_match('/>(.+?)<\\/LocationConstraint>/', $response->getBody(), $matches)) {
30 $location = $matches[1] === 'EU' ? 'eu-west-1' : $matches[1];
31 }
32 $result['LocationConstraint'] = $location;
33 }
34 return $result;
35 }
36 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
37 {
38 return $this->parser->parseMemberFromStream($stream, $member, $response);
39 }
40 }
41