Source of file ProtectedAdapter.php
Size: 2,096 Bytes - Last Modified: 2021-12-24T07:07:39+00:00
/var/www/docs.ssmods.com/process/src/src/Adapter/ProtectedAdapter.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | <?php namespace SilverStripe\S3\Adapter; use Aws\S3\S3Client; use InvalidArgumentException; use League\Flysystem\AwsS3v3\AwsS3Adapter; use SilverStripe\Assets\Flysystem\ProtectedAdapter as SilverstripeProtectedAdapter; /** * An adapter that allows the use of AWS S3 to store and transmit assets rather than storing them locally. */ class ProtectedAdapter extends AwsS3Adapter implements SilverstripeProtectedAdapter { /** * Pre-signed request expiration time in seconds, or relative string * * @var int|string */ protected $expiry = 300; public function __construct(S3Client $client, $bucket, $prefix = '', array $options = []) { if (!$bucket) { throw new InvalidArgumentException("AWS_BUCKET_NAME environment variable not set"); } if (!$prefix) { $prefix = 'protected'; } parent::__construct($client, $bucket, $prefix, $options); } /** * @return int|string */ public function getExpiry() { return $this->expiry; } /** * Set expiry. Supports either number of seconds (in int) or * a literal relative string. * * @param int|string $expiry * @return $this */ public function setExpiry($expiry) { $this->expiry = $expiry; return $this; } /** * @param string $path * * @return string */ public function getProtectedUrl($path) { $cmd = $this->getClient() ->getCommand('GetObject', [ 'Bucket' => $this->getBucket(), 'Key' => $this->applyPathPrefix($path), ]); // Format expiry $expiry = $this->getExpiry(); if (is_numeric($expiry)) { $expiry = "+{$expiry} seconds"; } return (string)$this->getClient() ->createPresignedRequest($cmd, $expiry) ->getUri(); } public function getVisibility($path) { // Save an API call return ['path' => $path, 'visibility' => self::VISIBILITY_PRIVATE]; } } |