Coder Social home page Coder Social logo

abstractstorage's Introduction

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());
}

abstractstorage's People

Contributors

alesinicio avatar

Stargazers

 avatar Komunica avatar Livfer avatar

Watchers

Pavel Vodička avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.