Get support for mnapoli/BlackBox

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

mnapoli/BlackBox


currentMenu: home

BlackBox

BlackBox is a storage library that abstracts backends and data transformation behind simple interfaces.

Build Status Latest Version

Store data. "Where" and "how" can be decided later.

Experimental: this project is still at the state of experimentation. Use with caution.

Usage

The API is defined by interfaces and is extremely simple.

namespace BlackBox;

interface Storage extends Traversable
{
    public function get(string $id);
    public function set(string $id, $data) : void;
    public function remove(string $id) : void;
}

$storage->set('foo', 'Hello World!');

echo $storage->get('foo'); // Hello World!

foreach ($storage as $key => $item) {
    echo $key; // foo
    echo $item; // Hello World!
}

You can read all about those interfaces in the Interfaces documentation.

Features

BlackBox can store data in:

  • files
  • database (MySQL, PostgreSQL, SQLite, Oracle, …) using Doctrine DBAL
  • PHP arrays (i.e. in memory)

Data can optionally be:

  • stored in JSON
  • stored in YAML
  • encrypted with AES

Additionally a storage can be cached with another (e.g. cache a DB storage with a Redis or array storage).

Backends

Backends are classes that implement Storage:

  • FileStorage
  • DirectoryStorage
  • DatabaseTable
  • ArrayStorage

You can read all about backends in the Backends documentation.

Transformers

Transformers transform data before storage and after retrieval:

  • JsonEncoder
  • YamlEncoder
  • ObjectArrayMapper
  • AesEncrypter

You can read all about transformers in the Transformers documentation.

// Encode the data in JSON
$storage = new JsonEncoder(
    // Store data in files
    new DirectoryStorage('some/directory')
);

$storage->set('foo', [
    'name' => 'Lebowski',
]);
// will encode it in JSON
// then will store it into a file

$data = $storage->get('foo');
// will read from the file
// then will decode the JSON

echo $data['name']; // Lebowski

License

BlackBox is released under the MIT license.

Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2