derywat/php-simple-storage
最新稳定版本:0.1.0
Composer 安装命令:
composer require derywat/php-simple-storage
包简介
Simple PHP library for storing key => value data.
README 文档
README
Caution
Interface and classes methods are NOT STABLE until anounced.
Overview
Library allows persisting data in key => value format using predefined or custom storage classes.
Included storage classes
JSON file storage (SimpleLocalStorageJSONFile class)
Class SimpleLocalStorageJSONFile uses JSON file for permanent storage.
Creating storage object:
$ps = new SimpleLocalStorageJSONFile(); $ps->setStorageFileName('storage/json_persisted_file.txt');
Created object contains values read from file.
Accessing values:
Accessing value by key:
$value = $ps->getValue('keyname');
Getting all stored values:
$allValues = $ps->getValues();
Persisting values:
Setting value automatically persist all values to file.
Value must be serializable in JSON format.
$ps->setValue('keyname',$value);
Unsetting value also persists all values to file.
$ps->unsetValue('keyname');
Implementing custom storage classes
Custom storage can be implemented by extending SimpleLocalStorage abstract class.
class NewSimpleStorageClass extends SimpleLocalStorage implements SimpleLocalStorageInterface { protected function _persist():void { //prepare $this->values for persistent storage //write or send data to storage or update changed data in storage } protected function _load():void { //load persisted data here $this->values = $loadedDataArray; } }
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-09