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\Crypto;
3
 
4
use Aws\Crypto\MaterialsProvider;
5
use Aws\Crypto\MetadataEnvelope;
6
use Aws\Crypto\MetadataStrategyInterface;
7
 
8
trait CryptoParamsTrait
9
{
10
    protected function getMaterialsProvider(array $args)
11
    {
12
        if ($args['@MaterialsProvider'] instanceof MaterialsProvider) {
13
            return $args['@MaterialsProvider'];
14
        }
15
 
16
        throw new \InvalidArgumentException('An instance of MaterialsProvider'
17
            . ' must be passed in the "MaterialsProvider" field.');
18
    }
19
 
20
    protected function getInstructionFileSuffix(array $args)
21
    {
22
        return !empty($args['@InstructionFileSuffix'])
23
            ? $args['@InstructionFileSuffix']
24
            : $this->instructionFileSuffix;
25
    }
26
 
27
    protected function determineGetObjectStrategy(
28
        $result,
29
        $instructionFileSuffix
30
    ) {
31
        if (isset($result['Metadata'][MetadataEnvelope::CONTENT_KEY_V2_HEADER])) {
32
            return new HeadersMetadataStrategy();
33
        }
34
 
35
        return new InstructionFileMetadataStrategy(
36
            $this->client,
37
            $instructionFileSuffix
38
        );
39
    }
40
 
41
    protected function getMetadataStrategy(array $args, $instructionFileSuffix)
42
    {
43
        if (!empty($args['@MetadataStrategy'])) {
44
            if ($args['@MetadataStrategy'] instanceof MetadataStrategyInterface) {
45
                return $args['@MetadataStrategy'];
46
            }
47
 
48
            if (is_string($args['@MetadataStrategy'])) {
49
                switch ($args['@MetadataStrategy']) {
50
                    case HeadersMetadataStrategy::class:
51
                        return new HeadersMetadataStrategy();
52
                    case InstructionFileMetadataStrategy::class:
53
                        return new InstructionFileMetadataStrategy(
54
                            $this->client,
55
                            $instructionFileSuffix
56
                        );
57
                    default:
58
                        throw new \InvalidArgumentException('Could not match the'
59
                            . ' specified string in "MetadataStrategy" to a'
60
                            . ' predefined strategy.');
61
                }
62
            } else {
63
                throw new \InvalidArgumentException('The metadata strategy that'
64
                    . ' was passed to "MetadataStrategy" was unrecognized.');
65
            }
66
        } elseif ($instructionFileSuffix) {
67
            return new InstructionFileMetadataStrategy(
68
                $this->client,
69
                $instructionFileSuffix
70
            );
71
        }
72
 
73
        return null;
74
    }
75
}