Caution
Interface and classes methods are NOT STABLE until anounced.
Library allows persisting data in key => value format using predefined or custom storage classes.
Class SimpleLocalStorageJSONFile uses JSON file for permanent storage.
$ps = new SimpleLocalStorageJSONFile();
$ps->setStorageFileName('storage/json_persisted_file.txt');Created object contains values read from file.
Accessing value by key:
$value = $ps->getValue('keyname');Getting all stored values:
$allValues = $ps->getValues();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');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;
}
}