2017 © Pedro PelĂĄez
 

library object-storage

Object storage

image

codeinc/object-storage

Object storage

  • Wednesday, March 14, 2018
  • by joanfabregat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 19 Versions
  • 0 % Grown

The README.md

PHP object storage library

This library, written in PHP 7, provides an abstraction layer for various cloud and local object storage plateforms including: * OpenStack Swift * BackBlaze B2 * SFTP * Local file system, (*1)

Usage

Initializing containers

use CodeInc\ObjectStorage;

// SFTP container with private key authentication
$sftpDirectory = ObjectStorage\Sftp\SftpDirectory::factoryPubKey(
    "/remote/path/to/files",
    "hostname.local",
    "remote-user",
    "path/to/public-key.pub",
    "path/to/private-key",
    "optional-key-passphrase"
    22 // optional port number
);

// SFTP container with user/password authentication
$sftpDirectory = ObjectStorage\Sftp\SftpDirectory::factoryPassword(
    "hostname.local",
    "remote-user",
    "remote-password",
    22 // optional port number
);

// Local file system container
$localDirectory = ObjectStorage\Local\LocalDirectory::factory(
    "/path/to/files"
);

// Swift container
$swiftContainer = ObjectStorage\Swift\SwiftContainer::factory(
    "container-name",
    "container-swift-region",
    "https://open-stack-auth-url.com",
    "open-stack-user",
    "open-stack-password",
    "open-stack-tenant-id",
    "open-stack-tenant-name"
);

// B2 container 
$b2Bucket = ObjectStorage\BackBlazeB2\B2Bucket::factory(
    "container-or-bucket-name",
    "b2-account-id",
    "b2-application-key"
);

Creating a file

use CodeInc\ObjectStorage;

// from an existing file
$object = new ObjectStorage\Utils\InlineObject("test.jpg");
$object->setFileContent("/path/to/test.jpg");

// from a string
$object = new ObjectStorage\Utils\InlineObject("test.txt");
$object->setStringContent("C'est un test au format texte !");

Uploading an object

// uploading an object
$container->uploadObject($object, 'optional-new-object-name.txt');

// transfering an object from a container to another
$destinationContainer->uploadObject(
    $sourceContainer->getObject('test.jpg')
);

Listing objects

foreach ($container as $file) {
    var_dump($file->getName());
}

$file is an object implementing the interface StoreObjectInterface., (*2)

Getting an object

header('Content-Type: image/jpeg');
echo $container->getObject('test.jpg')->getContent();

getObject() returns an object implementing the interface StoreObjectInterface., (*3)

Deleting an object

// from a container
$container->deleteObject("test.jpg");

// from an object
$object = $container->getObject('test.jpg');
if ($object instanceof StoreObjectDeleteInterface) {
    $object->delete();
}

For objects implementing the StoreObjectDeleteInterface you can call the delete() method directory on the object., (*4)

Installation

This library is available through Packagist and can be installed using Composer:, (*5)

composer require codeinc/object-storage

License

The library is published under the MIT license (see LICENSE file)., (*6)

The Versions

08/03 2018

1.3.6

1.3.6.0 https://github.com/CodeIncHQ/lib-objectstorage

Sophos backup tools

  Sources   Download

MIT

The Requires