-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
I think we could design some interfaces for working with different file storages, such as local file system, ftp, sftp, S3, RackSpace, etc.
Each storage can have several 'root directories' (containers, buckets).
It could be one interface, for instance (here $bucket is a string):
interface FileStorage
{
public function exists($bucketName, $fileName);
public function upload($bucketName, $sourceFile, $fileName);
public function download($bucketName, $fileName, $destinationFile);
public function write($bucketName, $fileName, $content);
public function read($bucketName, $fileName);
public function delete($bucketName, $fileName);
...
public function getUrl($bucketName, $fileName);
}
Now let think we have S3FileStorage implements FileStorage
.
$storage = new S3FileStorage();
$storage->configure([
'images' => ['baseUrl' => '...', ...] // Configure buckets, for example
]);
$storage->connect(...); // Connect to S3 server
$url = $storage->getUrl('images', 'logo.png');
Or 2 interfaces (the first one is for connection, the second one is for working with files), like:
interface FileStorage
{
public function addBucket($name, FileStorageBucket $bucket);
public function getBucket($name);
public function getBuckets();
}
and
interface FileStorageBucket
{
public function exists($fileName);
public function upload($sourceFile, $fileName);
public function download($fileName, $destinationFile);
public function write($fileName, $content);
public function read($fileName);
public function delete($fileName);
...
public function getUrl($fileName);
}
Now let think we have S3FileStorage implements FileStorage
and S3FileStorageBucket ...
$bucket = new S3FileStorageBucket();
$bucket->setBaseUrl(...);
$bucket->...
$storage = new S3FileStorage();
$storage->connect(...); // Connect to S3 server
$storage->addBucket('images', $bucket);
$url = $storage->getBucket('images')->getUrl('logo.png');
shadowhand and vladyslavvolkovegorio