Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace Aws\S3\Parser;
4
 
5
use Aws\CommandInterface;
6
use Aws\ResultInterface;
7
use Psr\Http\Message\ResponseInterface;
8
 
9
/**
10
 * A custom mutator for a GetBucketLocation request, which
11
 * extract the bucket location value and injects it into the
12
 * result as the `LocationConstraint` field.
13
 *
14
 * @internal
15
 */
16
final class GetBucketLocationResultMutator implements S3ResultMutator
17
{
18
    /**
19
     * @inheritDoc
20
     */
21
    public function __invoke(
22
        ResultInterface $result,
23
        CommandInterface $command,
24
        ResponseInterface $response
25
    ): ResultInterface
26
    {
27
        if ($command->getName() !== 'GetBucketLocation') {
28
            return $result;
29
        }
30
 
31
        static $location = 'us-east-1';
32
        static $pattern = '/>(.+?)<\/LocationConstraint>/';
33
        if (preg_match($pattern, $response->getBody(), $matches)) {
34
            $location = $matches[1] === 'EU' ? 'eu-west-1' : $matches[1];
35
        }
36
 
37
        $result['LocationConstraint'] = $location;
38
        $response->getBody()->rewind();
39
 
40
        return $result;
41
    }
42
}