AWS S3

<?php
$s3 = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('s3://access_key:[email protected]/bucket');

The full connection string can be:

s3://AKA12345678899:[email protected]/mybucket

You can add any extra arguments supported by the S3 api. You can get a full list here:

  • https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#___construct
  • https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html#___construct

One of the most populars is the parameter endpoint where we can set a custom endpoint to access an S3 compatible interface.

An example can be:

s3://AKA12345678899:[email protected]/mybucket?endpoint=http://localhost:9000

There is a specific parameter called create from anydataset/no-sql that permit create a bucket if it doesn't exist.

Example:

s3://AKA12345678899:[email protected]/mybucket?create=true

List all objects

<?php
$s3 = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('s3://....');
$iterator = $s3->getIterator();
print_r($iterator->toArray());

Inserting/Updating data

<?php
$s3 = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('s3://....');
$s3->put("object_name", "value");

Retrieve a value

<?php
$s3 = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('s3://....');
$value = $s3->get("object_name");

Remove a value

<?php
$s3 = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('s3://....');
$s3->remove("object_name");

Get parts of the document

<?php
$s3 = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('s3://....');

$size = 1024;
$offset = 0;
$data = $s3->getChunk("object_name", [], 1024, 0);
while (strlen($data) <= $size) {
    $data .= $s3->getChunk("object_name", [], 1024, 0);
}

Open source ByJG