Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws\S3;
3
 
4
use Aws\CommandInterface;
5
use Aws\ResultInterface;
6
use Psr\Http\Message\RequestInterface;
7
 
8
/**
9
 * Injects ObjectURL into the result of the PutObject operation.
10
 *
11
 * @internal
12
 */
13
class PutObjectUrlMiddleware
14
{
15
    /** @var callable  */
16
    private $nextHandler;
17
 
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
    /**
31
     * @param callable $nextHandler Next handler to invoke.
32
     */
33
    public function __construct(callable $nextHandler)
34
    {
35
        $this->nextHandler = $nextHandler;
36
    }
37
 
38
    public function __invoke(CommandInterface $command, RequestInterface $request = null)
39
    {
40
        $next = $this->nextHandler;
41
        return $next($command, $request)->then(
42
            function (ResultInterface $result) use ($command) {
43
                $name = $command->getName();
44
                switch ($name) {
45
                    case 'PutObject':
46
                    case 'CopyObject':
47
                        $result['ObjectURL'] = isset($result['@metadata']['effectiveUri'])
48
                            ? $result['@metadata']['effectiveUri']
49
                            : null;
50
                        break;
51
                    case 'CompleteMultipartUpload':
52
                        $result['ObjectURL'] = $result['Location'];
53
                        break;
54
                }
55
                return $result;
56
            }
57
        );
58
    }
59
}