PHP Класс JSONStorage

Provides a very simple way to persistent JSON storage. Acts as a registry key saver. Example of use: $j = new JSONStorage(); $j->addRegistry('custom'); echo $j->registryExists('custom'); $j->setData('mydata','super','custom'); $j->save(); $j->load(); echo $j->getData('super','custom');
Наследование: extends CComponent
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$data the data of the registry
$default the name of the default registry
$dirty whether the registry has changed or not
$filename the filename to save the values to
$path the full path to the directory with read/write access to save the registry to. If none set, the component will used the application's runtime folder

Открытые методы

Метод Описание
__construct ( null $registry = null ) class constructor
__destruct ( ) class destructor - flush data
addRegistry ( string $registry ) : boolean Add new collection name
getData ( string $key, null $registry = null ) : mixed Retrieves a data value from the registry
getFile ( ) : string Property get file
getLength ( null $registry = null ) : integer Retrieves the number of keys in registry
getPath ( ) : string Property get path
getRegistry ( string $registry ) : mixed | null Retrieves a registry collection based on its name
load ( ) Loads registry data into memory
onAfterSave ( CEvent $event ) Fires after the registry has been saved
onBeforeSave ( CEvent $event ) Fires before registry has been saved
registryExists ( string $registry ) : boolean Checkes whether a collection exists (registry)
removeData ( string $key, null $registry = null ) : boolean Removes data from a key in the registry
removeRegistry ( string $registry ) : boolean Remove an existing collection and all associated data
save ( ) Saves registry data to the file
setData ( string $key, array $data, null $registry = null ) : boolean Saves data to the registry
setFile ( string $file ) Property set file
setPath ( string $path ) : boolean Property set path
verify ( ) : boolean Verifies data integrity

Приватные методы

Метод Описание
decode ( string $data ) : mixed JSON decodes the data
encode ( string $data ) : string JSON encodes the data
flush ( ) : boolean Saves the global registry to the file

Описание методов

__construct() публичный Метод

class constructor
public __construct ( null $registry = null )
$registry null

__destruct() публичный Метод

class destructor - flush data
public __destruct ( )

addRegistry() публичный Метод

Add new collection name
public addRegistry ( string $registry ) : boolean
$registry string the name of the registry (collection) to create
Результат boolean

getData() публичный Метод

Retrieves a data value from the registry
public getData ( string $key, null $registry = null ) : mixed
$key string the name of the key that holds the data
$registry null the registry name
Результат mixed the data in the key value, null otherwise

getFile() публичный Метод

Property get file
public getFile ( ) : string
Результат string filename

getLength() публичный Метод

Retrieves the number of keys in registry
public getLength ( null $registry = null ) : integer
$registry null the registry name
Результат integer the data length

getPath() публичный Метод

Property get path
public getPath ( ) : string
Результат string

getRegistry() публичный Метод

Retrieves a registry collection based on its name
public getRegistry ( string $registry ) : mixed | null
$registry string the name of the registry to retrieve
Результат mixed | null the registry, null if none found

load() публичный Метод

Loads registry data into memory
public load ( )

onAfterSave() публичный Метод

Fires after the registry has been saved
public onAfterSave ( CEvent $event )
$event CEvent

onBeforeSave() публичный Метод

Fires before registry has been saved
public onBeforeSave ( CEvent $event )
$event CEvent

registryExists() публичный Метод

Checkes whether a collection exists (registry)
public registryExists ( string $registry ) : boolean
$registry string the name of the registry to check existence
Результат boolean

removeData() публичный Метод

Removes data from a key in the registry
public removeData ( string $key, null $registry = null ) : boolean
$key string the key name that holds the data to remove
$registry null the registry name
Результат boolean true if successful, false otherwise

removeRegistry() публичный Метод

Remove an existing collection and all associated data
public removeRegistry ( string $registry ) : boolean
$registry string the name of the registry to remove
Результат boolean

save() публичный Метод

Saves registry data to the file
public save ( )

setData() публичный Метод

Saves data to the registry
public setData ( string $key, array $data, null $registry = null ) : boolean
$key string the name of the key that will hold the data
$data array the data to save
$registry null the name of the registry
Результат boolean

setFile() публичный Метод

Property set file
public setFile ( string $file )
$file string the filename to save the registry to

setPath() публичный Метод

Property set path
public setPath ( string $path ) : boolean
$path string the full path of the directory with read/write access to save the registry file to
Результат boolean

verify() публичный Метод

Verifies data integrity
public verify ( ) : boolean
Результат boolean

Описание свойств

$data защищенное свойство

the data of the registry
protected $data

$default защищенное свойство

the name of the default registry
protected $default

$dirty защищенное свойство

whether the registry has changed or not
protected $dirty

$filename защищенное свойство

the filename to save the values to
protected $filename

$path защищенное свойство

the full path to the directory with read/write access to save the registry to. If none set, the component will used the application's runtime folder
protected $path