PHP Classes

PHP Cloud Storage Abstraction: Store and retrieve data in multiple cloud services

Recommend this page to a friend!
  Info   View files Example   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 234 All time: 8,086 This week: 87Up
Version License PHP version Categories
abstractstorage 1.000.000GNU General Publi...5PHP 5, Files and Folders, Web services
Description 

Author

This package can store and retrieve data in multiple cloud services.

It provides a common interface to access different storage services that implement functions like listing, uploading, downloading and deleting files.

Currently it provides classes that implement the storage interface to access Amazon S3 and local files storage. Others can be provided in the future by implementing the same interface.

Innovation Award
PHP Programming Innovation award nominee
March 2018
Number 5
Nowadays there are many cloud services that provide services for hosting data files.

This package provide an abstraction, so developers can use different cloud data storage provides to store and retrieve files.

Manuel Lemos
Picture of Alexandre Sinício
  Performance   Level  
Name: Alexandre Sinício <contact>
Classes: 7 packages by
Country: Brazil Brazil
Age: 39
All time rank: 2097136 in Brazil Brazil
Week rank: 101 Up9 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
use SinFramework\Storage\LocalStorage;

require
'../bootstrap.php';
require
'../vendor/autoload.php';

//OUR GLOBAL VARS FOR THIS EXAMPLE
$file = 'demo.txt';
$bucket = 'mybucket';

//GET STORAGE OBJECT
$storage = getStorageObj();

//PUT FILE INTO BUCKET AND GET UID THAT WAS GENERATED
try {
   
$fileUID = $storage->putFile($file, $bucket);
} catch (
Exception $e) {
    die(
$e->getMessage());
}

//THIS FUNCTION IS RESPONSIBLE FOR CREATING AND SETTING UP THE STORAGE OBJECT
//IN A REAL WORLD APPLICATION, IT SHOULD BE CONTAINED IN SOME KIND OF DEPENDENCY INJECTOR CONTAINER
/**
 * @return \SinFramework\Storage\StorageInterface
 */
function getStorageObj() {
   
$storageObj = new LocalStorage();
   
$storageObj::setBaseStorageLocation('../storage');
   
    return
$storageObj;
}


Details

Abstract Storage

Storing and retrieving files with PHP is easy... right?

Yes, it is, until you find out that you were storing files in your local server and now needs to change that to Amazon S3, Google or whatever.

You hard-coded a lot of stuff in your code, and when you start to "rewire" stuff, everything starts to break. It hurts.

The objective of this repo is to create an interface for file storage. This allow us to separate the implementation for each storage provider and the actual code which just want to store/retrieve/delete a file.

The basic implementation for local storage and Amazon S3 are included.

Feel free to contribute, criticize, extend and use.

Terminology

Some storage providers use different terminology for stuff. It can lead to confusion, and there's no way around it except choosing what seems the "best fit" for everything.

We use the term bucket on the interface as a way to represent a logic place where files are stored. In Amazon S3, that is a native term. In local storage, bucket just means directory/folder.

Dependencies

The interface itself does not have any dependencies. However the Amazon S3 implementation does. I suggest to use Composer and get the "aws/aws-sdk-php" package. Everything should be there.

Examples

Basic general examples

//OBJECT CREATION/INITIALIZATION -- SHOULD BE IN YOUR DEPENDENCY INJECTOR CONTAINER
$storageObj = new LocalStorage();
$storageObj::setBaseStorageLocation('../storage');

//ARCHIVE A FILE
try {
	$fileUID = $storage->putFile('myfile.txt', 'mybucket');
} catch (Exception $e) {
	die($e->getMessage());
}

//DOWNLOAD A FILE
try {
	$storage->getFile($fileUID, 'output_name.txt', 'mybucket');
} catch (Exception $e) {
	die($e->getMessage());
}

  Files folder image Files  
File Role Description
Files folder imageexamples (4 files)
Files folder imagevendor (1 directory)
Accessible without login Plain text file bootstrap.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file 01-adding-file.php Example Example script
  Accessible without login Plain text file 02-downloading-file.php Example Example script
  Accessible without login Plain text file 03-deleting-file.php Example Example script
  Accessible without login Plain text file 04-calculating-used-quota.php Example Example script

  Files folder image Files  /  vendor  
File Role Description
Files folder imageSinFramework (1 directory)

  Files folder image Files  /  vendor  /  SinFramework  
File Role Description
Files folder imageStorage (4 files)

  Files folder image Files  /  vendor  /  SinFramework  /  Storage  
File Role Description
  Plain text file AWSS3Storage.php Class Class source
  Plain text file LocalStorage.php Class Class source
  Plain text file StorageCommon.php Class Class source
  Plain text file StorageInterface.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:234
This week:0
All time:8,086
This week:87Up