mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Add S3 and Wasabi as storage providers (#281)
This commit is contained in:
74
app/StorageProviders/S3AbstractStorageProvider.php
Normal file
74
app/StorageProviders/S3AbstractStorageProvider.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\StorageProvider;
|
||||
use Aws\S3\S3Client;
|
||||
|
||||
abstract class S3AbstractStorageProvider extends AbstractStorageProvider implements S3ClientInterface, S3StorageInterface
|
||||
{
|
||||
protected ?string $apiUrl = null;
|
||||
|
||||
protected ?string $bucketRegion = null;
|
||||
|
||||
protected ?S3Client $client = null;
|
||||
|
||||
protected StorageProvider $storageProvider;
|
||||
|
||||
protected array $clientConfig = [];
|
||||
|
||||
public function getApiUrl(): string
|
||||
{
|
||||
return $this->apiUrl;
|
||||
}
|
||||
|
||||
public function setApiUrl(?string $region = null): void
|
||||
{
|
||||
$this->bucketRegion = $region ?? $this->bucketRegion;
|
||||
$this->apiUrl = "https://s3.{$this->bucketRegion}.amazonaws.com";
|
||||
}
|
||||
|
||||
public function getBucketRegion(): string
|
||||
{
|
||||
return $this->bucketRegion;
|
||||
}
|
||||
|
||||
public function setBucketRegion(string $region): void
|
||||
{
|
||||
$this->bucketRegion = $region;
|
||||
}
|
||||
|
||||
public function getClient(): S3Client
|
||||
{
|
||||
return new S3Client($this->clientConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the configuration array for the S3 client.
|
||||
* This method can be overridden by child classes to modify the configuration.
|
||||
*/
|
||||
public function buildClientConfig(): array
|
||||
{
|
||||
$this->clientConfig = [
|
||||
'credentials' => [
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
'secret' => $this->storageProvider->credentials['secret'],
|
||||
],
|
||||
'region' => $this->getBucketRegion(),
|
||||
'version' => 'latest',
|
||||
'endpoint' => $this->getApiUrl(),
|
||||
];
|
||||
|
||||
return $this->clientConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or update a configuration parameter for the S3 client.
|
||||
*/
|
||||
public function setConfigParam(array $param): void
|
||||
{
|
||||
foreach ($param as $key => $value) {
|
||||
$this->clientConfig[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user