\JSONStorage

## JSON Storage

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');

Summary

Methods
Properties
Constants
__construct()
__destruct()
onBeforeSave()
onAfterSave()
setPath()
getPath()
setFile()
getFile()
verify()
load()
save()
setData()
getData()
removeData()
getLength()
getRegistry()
registryExists()
addRegistry()
removeRegistry()
No public properties found
META
REGISTRY
No protected methods found
$filename
$path
$dirty
$default
$data
N/A
flush()
encode()
decode()
No private properties found
N/A

Constants

META

META

const string the key to keep value information

REGISTRY

REGISTRY

const string the key of the registry

Properties

$filename

$filename : string

Type

string — the filename to save the values to

$path

$path : string

Type

string — 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

$dirty

$dirty : bool

Type

bool — whether the registry has changed or not

$default

$default : null|string

Type

null|string — the name of the default registry

$data

$data : array

Type

array — the data of the registry

Methods

__construct()

__construct(null $registry)

class constructor

Parameters

null $registry

__destruct()

__destruct()

class destructor - flush data

onBeforeSave()

onBeforeSave(\CEvent $event)

Fires before registry has been saved

Parameters

\CEvent $event

onAfterSave()

onAfterSave(\CEvent $event)

Fires after the registry has been saved

Parameters

\CEvent $event

setPath()

setPath(string $path) : bool

Property set path

Parameters

string $path

the full path of the directory with read/write access to save the registry file to

Throws

\Exception

Returns

bool

getPath()

getPath() : string

Property get path

Returns

string

setFile()

setFile(string $file)

Property set file

Parameters

string $file

the filename to save the registry to

getFile()

getFile() : string

Property get file

Returns

string —

filename

verify()

verify() : bool

Verifies data integrity

Returns

bool

load()

load()

Loads registry data into memory

Throws

\Exception

save()

save()

Saves registry data to the file

setData()

setData(string $key, array $data, null $registry) : bool

Saves data to the registry

Parameters

string $key

the name of the key that will hold the data

array $data

the data to save

null $registry

the name of the registry

Returns

bool

getData()

getData(string $key, null $registry) : mixed

Retrieves a data value from the registry

Parameters

string $key

the name of the key that holds the data

null $registry

the registry name

Returns

mixed —

the data in the key value, null otherwise

removeData()

removeData(string $key, null $registry) : bool

Removes data from a key in the registry

Parameters

string $key

the key name that holds the data to remove

null $registry

the registry name

Returns

bool —

true if successful, false otherwise

getLength()

getLength(null $registry) : int

Retrieves the number of keys in registry

Parameters

null $registry

the registry name

Returns

int —

the data length

getRegistry()

getRegistry(string $registry) : mixed|null

Retrieves a registry collection based on its name

Parameters

string $registry

the name of the registry to retrieve

Returns

mixed|null —

the registry, null if none found

registryExists()

registryExists(string $registry) : bool

Checkes whether a collection exists (registry)

Parameters

string $registry

the name of the registry to check existence

Returns

bool

addRegistry()

addRegistry(string $registry) : bool

Add new collection name

Parameters

string $registry

the name of the registry (collection) to create

Returns

bool

removeRegistry()

removeRegistry(string $registry) : bool

Remove an existing collection and all associated data

Parameters

string $registry

the name of the registry to remove

Returns

bool

flush()

flush() : bool

Saves the global registry to the file

Throws

\Exception

Returns

bool

encode()

encode(string $data) : string

JSON encodes the data

Parameters

string $data

Returns

string

decode()

decode(string $data) : mixed

JSON decodes the data

Parameters

string $data

Returns

mixed