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