PHP Class 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');
Inheritance: extends CComponent
Afficher le fichier Open project: yinhe/yincart

Protected Properties

Свойство Type Description
$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

Méthodes publiques

Méthode Description
__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

Private Methods

Méthode Description
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

Method Details

__construct() public méthode

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

__destruct() public méthode

class destructor - flush data
public __destruct ( )

addRegistry() public méthode

Add new collection name
public addRegistry ( string $registry ) : boolean
$registry string the name of the registry (collection) to create
Résultat boolean

getData() public méthode

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
Résultat mixed the data in the key value, null otherwise

getFile() public méthode

Property get file
public getFile ( ) : string
Résultat string filename

getLength() public méthode

Retrieves the number of keys in registry
public getLength ( null $registry = null ) : integer
$registry null the registry name
Résultat integer the data length

getPath() public méthode

Property get path
public getPath ( ) : string
Résultat string

getRegistry() public méthode

Retrieves a registry collection based on its name
public getRegistry ( string $registry ) : mixed | null
$registry string the name of the registry to retrieve
Résultat mixed | null the registry, null if none found

load() public méthode

Loads registry data into memory
public load ( )

onAfterSave() public méthode

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

onBeforeSave() public méthode

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

registryExists() public méthode

Checkes whether a collection exists (registry)
public registryExists ( string $registry ) : boolean
$registry string the name of the registry to check existence
Résultat boolean

removeData() public méthode

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
Résultat boolean true if successful, false otherwise

removeRegistry() public méthode

Remove an existing collection and all associated data
public removeRegistry ( string $registry ) : boolean
$registry string the name of the registry to remove
Résultat boolean

save() public méthode

Saves registry data to the file
public save ( )

setData() public méthode

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
Résultat boolean

setFile() public méthode

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

setPath() public méthode

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
Résultat boolean

verify() public méthode

Verifies data integrity
public verify ( ) : boolean
Résultat boolean

Property Details

$data protected_oe property

the data of the registry
protected $data

$default protected_oe property

the name of the default registry
protected $default

$dirty protected_oe property

whether the registry has changed or not
protected $dirty

$filename protected_oe property

the filename to save the values to
protected $filename

$path protected_oe property

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