| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\S3\Crypto; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Crypto\MetadataStrategyInterface; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\Crypto\MetadataEnvelope; |
| 7 |
class HeadersMetadataStrategy implements MetadataStrategyInterface |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Places the information in the MetadataEnvelope in to the metadata for |
| 11 |
* the PutObject request of the encrypted object. |
| 12 |
* |
| 13 |
* @param MetadataEnvelope $envelope Encryption data to save according to |
| 14 |
* the strategy. |
| 15 |
* @param array $args Arguments for PutObject that can be manipulated to |
| 16 |
* store strategy related information. |
| 17 |
* |
| 18 |
* @return array Updated arguments for PutObject. |
| 19 |
*/ |
| 20 |
public function save(MetadataEnvelope $envelope, array $args) |
| 21 |
{ |
| 22 |
foreach ($envelope as $header => $value) { |
| 23 |
$args['Metadata'][$header] = $value; |
| 24 |
} |
| 25 |
return $args; |
| 26 |
} |
| 27 |
/** |
| 28 |
* Generates a MetadataEnvelope according to the metadata headers from the |
| 29 |
* GetObject result. |
| 30 |
* |
| 31 |
* @param array $args Arguments from Command and Result that contains |
| 32 |
* S3 Object information, relevant headers, and command |
| 33 |
* configuration. |
| 34 |
* |
| 35 |
* @return MetadataEnvelope |
| 36 |
*/ |
| 37 |
public function load(array $args) |
| 38 |
{ |
| 39 |
$envelope = new MetadataEnvelope(); |
| 40 |
$constantValues = MetadataEnvelope::getConstantValues(); |
| 41 |
foreach ($constantValues as $constant) { |
| 42 |
if (!empty($args['Metadata'][$constant])) { |
| 43 |
$envelope[$constant] = $args['Metadata'][$constant]; |
| 44 |
} |
| 45 |
} |
| 46 |
return $envelope; |
| 47 |
} |
| 48 |
} |
| 49 |
|