| 1 |
<?php |
| 2 |
namespace Aws\S3; |
| 3 |
|
| 4 |
use Aws\Api\Parser\AbstractParser; |
| 5 |
use Aws\Api\StructureShape; |
| 6 |
use Aws\CommandInterface; |
| 7 |
use Psr\Http\Message\ResponseInterface; |
| 8 |
use Psr\Http\Message\StreamInterface; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class GetBucketLocationParser extends AbstractParser |
| 15 |
{ |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public function __construct(callable $parser) |
| 20 |
{ |
| 21 |
$this->parser = $parser; |
| 22 |
} |
| 23 |
|
| 24 |
public function __invoke( |
| 25 |
CommandInterface $command, |
| 26 |
ResponseInterface $response |
| 27 |
) { |
| 28 |
$fn = $this->parser; |
| 29 |
$result = $fn($command, $response); |
| 30 |
|
| 31 |
if ($command->getName() === 'GetBucketLocation') { |
| 32 |
$location = 'us-east-1'; |
| 33 |
if (preg_match('/>(.+?)<\/LocationConstraint>/', $response->getBody(), $matches)) { |
| 34 |
$location = $matches[1] === 'EU' ? 'eu-west-1' : $matches[1]; |
| 35 |
} |
| 36 |
$result['LocationConstraint'] = $location; |
| 37 |
} |
| 38 |
|
| 39 |
return $result; |
| 40 |
} |
| 41 |
|
| 42 |
public function parseMemberFromStream( |
| 43 |
StreamInterface $stream, |
| 44 |
StructureShape $member, |
| 45 |
$response |
| 46 |
) { |
| 47 |
return $this->parser->parseMemberFromStream($stream, $member, $response); |
| 48 |
} |
| 49 |
} |