HeadersMetadataStrategy.php 1.6 KB

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