mnapoli/blackbox

0.6.1 2015-01-10 01:47 UTC

This package is auto-updated.

Last update: 2024-09-19 21:06:08 UTC


README

BlackBox

BlackBox是一个存储库,它通过简单的接口抽象了后端和数据转换。

Build Status Latest Version

存储数据。 "在哪里" 和 "如何" 可以稍后决定。

实验性:该项目仍处于实验阶段。请谨慎使用。

使用方法

API 由接口定义,非常简单。

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!
}

您可以在接口文档中了解有关这些接口的所有信息。

特性

BlackBox可以在以下位置存储数据:

  • 文件
  • 数据库(MySQL、PostgreSQL、SQLite、Oracle等)使用Doctrine DBAL
  • PHP数组(即内存中)

数据可以选择存储为:

  • JSON
  • YAML
  • 使用AES加密

此外,可以将存储与另一个存储(例如,使用Redis或数组存储缓存数据库存储)进行缓存。

后端

后端是实现Storage类的类

  • FileStorage
  • DirectoryStorage
  • DatabaseTable
  • ArrayStorage

您可以在后端文档中了解有关后端的所有信息。

转换器

转换器在存储之前和检索之后转换数据

  • JsonEncoder
  • YamlEncoder
  • ObjectArrayMapper
  • AesEncrypter

您可以在转换器文档中了解有关转换器的所有信息。

// 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

许可证

BlackBox在MIT许可证下发布。