This commit is contained in:
Cyprian Beauvois 2019-02-20 12:36:07 +01:00
parent 405d854c01
commit fb171e0655
2 changed files with 12 additions and 32 deletions

View File

@ -25,6 +25,8 @@ class S3Storage
$this->config = $config;
$this->bucket = $config['bucket'];
dump($this); die;
$this->client = new S3Client([
'version' => isset($config['version']) ? $config['version'] : 'latest',
'region' => $config['region'],

View File

@ -3,6 +3,7 @@
namespace Bluesquare\StorageBundle;
use Aws\S3\S3Client;
use Bluesquare\StorageBundle\Adaptors\S3Storage;
/**
* Interface de manipulation des stockages préconfigurés
@ -10,46 +11,23 @@ use Aws\S3\S3Client;
*/
class Storage
{
private $user_config = [];
private $config_storage = [];
public function __construct(array $user_config = [])
{
$this->user_config = $user_config;
$this->config_storage = $user_config;
}
public function get($storage_name)
{
// TODO: on récupère les infos sur ce storage dans la config utilisateur (config/bluesquare/storage.yaml)
// La clef pour la configuration d'un storage devrait être : "storage.{storage_name}"
if (array_key_exists($storage_name, $this->config_storage))
{
$config = $this->config_storage[$storage_name];
// dump($this); die;
// Si storage.{storage_name}.type == 's3' alors :
// return new S3Storage($storage_name, $config); // $config c'est le contenu de storage.{storage_name} sous forme de tableau
// Sinon :
return null; // (on ajoutera d'autres types de stockage plus tard, dont le stockage de fichier sur le serveur actuel)
}
if ($config['type'] == 's3')
return new S3Storage($storage_name, $config);
}
//storage:
//photos:
// type: s3
// bucket: bluesquare.public
// region: nl-ams
// endpoint: 'https://s3.nl-ams.scw.cloud'
// credentials:
// key: '%env(MYSUPERSECRETAWSKEY)%'
// secret: '%env(MYSUPERSECRETAWSSECRET)%'
// version: lastest # optionnel
// path: '/photos' # optionnel
//
// files:
// type: s3
// bucket: bluesquare.private
// region: nl-ams
// endpoint: 'https://s3.nl-ams.scw.cloud'
// credentials:
// key: '%env(MYSUPERSECRETAWSKEY)%'
// secret: '%env(MYSUPERSECRETAWSSECRET)%'
//
// ...
return null;
}
}