irfantoor / datastore
键值对数据存储
0.4.1
2021-01-22 23:02 UTC
Requires
- php: >= 7.3
- irfantoor/database: ~0.4
- irfantoor/filesystem: ~0.3
Requires (Dev)
- irfantoor/test: ~0.7
README
将键值对存储到文件系统
快速开始
安装或包含到您的项目中
$ composer require irfantoor/datastore
创建数据存储
$ds = new IrfanTOOR\Datastore('/yourpath/to/datatore/');
has($id)
验证存储中是否存在具有请求ID的实体。返回true或false
$ds = new IrfanTOOR\Datastore('/yourpath/to/datatore/'); if ($ds->has('hello')) { echo $ds->get('hello'); }
set($id, $value, $meta = [])
设置ID的值
$ds->set('hello', 'Hello'); $ds->set('hello-world', 'Hello World!'); # ...
有关其他信息的任何其他信息都可以使用第三个参数$meta进行存储。
$meta = [ 'meta' => [ 'keywords' => 'hello, world', 'author' => 'Jhon Doe', # ... ]; ]; $ds->setComponents('hello', 'Hello World!', $meta);
info($id)
您可以使用info
函数检索实体的信息
$info = $ds->info('hello-world'); print_r($info); # Note: the information does not contain the value, which can be retrieved using # the get function
get($id)
返回与ID关联的值
$contents = $ds->get('hello', 'Hello'); echo $contents; echo $ds->get('hello-world');
remove($id)
删除与提供的ID关联的实体
$ds->remove('hello');
addFile($key, $file, $meta = [])
您可以使用此函数将文件添加到数据存储中。
$file = 'absolute\path\to\your\reference_file.txt'; $ds->addFile('reference', $file); # or you can add some meta information $ds->addFile('reference', $file, ['keywords' => 'reference', 'sites', 'index', '...']);