suffix = empty($suffix) ? self::DEFAULT_FILE_SUFFIX : $suffix; $this->client = $client; } /** * Places the information in the MetadataEnvelope to a location on S3. * * @param MetadataEnvelope $envelope Encryption data to save according to * the strategy. * @param array $args Starting arguments for PutObject, used for saving * extra the instruction file. * * @return array Updated arguments for PutObject. */ public function save(MetadataEnvelope $envelope, array $args) { $this->client->putObject([ 'Bucket' => $args['Bucket'], 'Key' => $args['Key'] . $this->suffix, 'Body' => json_encode($envelope) ]); return $args; } /** * Uses the strategy's client to retrieve the instruction file from S3 and generates * a MetadataEnvelope from its contents. * * @param array $args Arguments from Command and Result that contains * S3 Object information, relevant headers, and command * configuration. * * @return MetadataEnvelope */ public function load(array $args) { $result = $this->client->getObject([ 'Bucket' => $args['Bucket'], 'Key' => $args['Key'] . $this->suffix ]); $metadataHeaders = json_decode($result['Body'], true); $envelope = new MetadataEnvelope(); $constantValues = MetadataEnvelope::getConstantValues(); foreach ($constantValues as $constant) { if (!empty($metadataHeaders[$constant])) { $envelope[$constant] = $metadataHeaders[$constant]; } } return $envelope; } }