Storage mechanism for the Commentar project. This storage mechanism requires no database, but rather stores the data encoded in the JSON format on the filesystem.
This should only be used for development purposes to have a portable way of introducing some persistent storage. It should never be used in production.
Add the storage mechanism to the project's composer.json
file:
"require": {
"commentar/json-storage": "0.0.*",
}
Add the default admin user in the /data/users.json
file:
{
"autoincrement": 1,
"users": {
"1": {
"id": 1,
"username": "PeeHaa",
"password": "$2y$14$Usk4vuNbzowQihbscOZjcu6RRzPBK3zIn79F8wn.bjczbElrqzbJu",
"email": "[email protected]",
"isHellbanned": false,
"isAdmin": true
}
}
}
The password should be hashed using PHP's native password hashing function (password_hash()
). The easiest way to generate the password hash is by either using this service or by manually running the password hashing function: echo password_hash('Your super secret password', PASSWORD_DEFAULT, ['cost' => 14]);
.
To start using the storage you will have to start using the provided datamapper factory by this library. An example of retrieving the comment tree of a thread is:
$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);