commentar/json-storage

此存储机制无需数据库,而是在文件系统上存储以 JSON 格式编码的数据。

v0.0.6 2013-10-05 21:01 UTC

This package is auto-updated.

Last update: 2024-09-06 09:50:55 UTC


README

Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version Total Downloads

Commentar 项目提供的存储机制。此存储机制无需数据库,而是在文件系统上存储以 JSON 格式编码的数据。

这仅应用于开发目的,以便以可移植的方式引入一些持久存储。它 绝不应 在生产中使用。

安装

将存储机制添加到项目的 composer.json 文件

"require": {
    "commentar/json-storage": "0.0.*",
}

/data/users.json 文件中添加默认管理员用户

{
    "autoincrement": 1,
    "users": {
        "1": {
            "id": 1,
            "username": "PeeHaa",
            "password": "$2y$14$Usk4vuNbzowQihbscOZjcu6RRzPBK3zIn79F8wn.bjczbElrqzbJu",
            "email": "your@mail.com",
            "isHellbanned": false,
            "isAdmin": true
        }
    }
}

密码应使用 PHP 的原生密码散列函数(password_hash())进行散列。生成密码散列的最简单方法是通过使用 此服务 或手动运行密码散列函数:echo password_hash('Your super secret password', PASSWORD_DEFAULT, ['cost' => 14]);

要开始使用存储,您将不得不开始使用此库提供的 datamapper 工厂。检索线程评论树的示例是

$domainObjectFactory = new \Commentar\DomainObject\Factory();
$datamapperFactory   = new \Commentar\Storage\Json\Factory(__DIR__ . '/vendor/commentar/json-storage/data');
$commentService      = new \Commentar\Service\Comment($domainObjectFactory, $datamapperFactory);

$commentTree = $commentService->getTree(1);