pop-storage

The popphp/pop-storage is a storage wrapper component that provides interchangeable adapters to easily manage and switch between different storage resources, such as the local disk or a cloud-based storage platform, like AWS S3.

Installation

Install it directly into your project:

composer require popphp/pop-storage

Or, include it in your composer.json file:

{
    "require": {
        "popphp/pop-storage": "^1.0.0"
    }
}

Basic Use

Setting up the Local adapter

$storage = new Pop\Storage\Local(__DIR__ . '/tmp/');

Setting up the S3 adapter

$storage = new Pop\Storage\S3($_ENV['AWS_BUCKET'], new S3\S3Client([
    'credentials' => [
        'key'    => $_ENV['AWS_KEY'],
        'secret' => $_ENV['AWS_SECRET'],
    ],
    'region'  => $_ENV['AWS_REGION'],
    'version' => $_ENV['AWS_VERSION']
]));

Checking if a file exists

if ($storage->fileExists('test.txt')) {
    // File exists
}

Fetch contents of a file

$fileContents = $storage->fetchFile('test.txt');

Copy a file

$adapter->copyFile('test.txt', 'test2.txt');

Rename a file

$adapter->renameFile('test.txt', 'test1.txt');

Replace a file

$adapter->replaceFile('test1.txt', 'new contents');

Make a directory

$adapter->mkdir('test');

Remove a directory

$adapter->rmdir('test');