=============================================================
MANUAL
=============================================================
Install:
Copy Data_Registry.php to a plugin/library directory as you desire.
Include file Data_Registry.php in your index.php or in your config file.
Enable sessions in your php.ini file.
If you use cookies or files, it will work as is.
Optional: To see examples, copy dr_examples.php and dr_testclass.php in your web base directory
Change default values (:
Set Storage Method to Files (by default, Session):
Data_Registry::init()->setStorageType('Files',"/tmp/DRFiles",3600);
// /tmp/DRFiles is the directory to store namespaces, must to exists
// 3600 is TTL (time to live) - expiration time
Enable global persistence (by default is disabled):
Data_Registry::setPersistence(TRUE,TRUE);
Set SESSION varname (by default is 'Data_Registry'):
Data_Registry::setSessionName('SESSIONNAMEVAR');
// SESSIONAMEVAR - Your desired session name var, as you have in your session handler
Set a value:
Data_Registry::init('NAMESPACE')->set('VAR','VALUE');
// Namespace can be any string;
// VAR is the varname to store
// VALUE is the value to store, can be string/integer/array/object
Get a value:
Data_Registry::init('NAMESPACE')->get('VAR');
// Namespace can be any string;
// VAR is the varname to get from store
// RETURNS value or FALSE
Set a key to a value:
Data_Registry::init('NAMESPACE')->setKey('VAR','KEY','VALUE');
// Namespace can be any string;
// VAR is the varname to store
// KEY is the varname index to store
// VALUE is the value to store, can be string/integer/array/object
Get a key from a varname stored:
Data_Registry::init('NAMESPACE')->getKey('VAR','KEY');
// Namespace can be any string;
// VAR is the varname to store
// KEY is the varname index to store
// RETURNS value or FALSE
Add a key value:
Data_Registry::init('NAMESPACE')->add('VAR','VALUE');
// Namespace can be any string;
// VAR is the varname to store
// VALUE is the value to store, can be string/integer/array/object
// VALUE is added in a array sequence to VAR
Test a value:
Data_Registry::init('NAMESPACE')->test('VAR');
// Namespace can be any string;
// VAR is the varname to test
// RETURN boolean TRUE=exists, FALSE=not exists
Test a key value:
Data_Registry::init('NAMESPACE')->testKey('VAR','KEY');
// Namespace can be any string;
// VAR is the varname to test
// KEY is the key to test
// RETURN boolean TRUE=exists, FALSE=not exists
Enable global persistence for all namespaces:
Data_Registry::setPersistence(TRUE,TRUE);
Disable global persistence for all namespaces:
Data_Registry::setPersistence(FALSE,TRUE);
Enable persistence for a namespace (when global persistence is disabled):
Data_Registry::init('NAMESPACE')->setPersistence(TRUE);
Disable persistence for a namespace (when global persistence is disabled):
Data_Registry::init('NAMESPACE')->setPersistence(TRUE);
Get all data from a namespace:
Data_Registry::init('NAMESPACE')->getNameSpace();
// RETURNS an array
Get all data from all namespaces:
Data_Registry::getAllNameSpaces();
// RETURNS an array
Clear (unset) a var from namespace:
Data_Registry::init('NAMESPACE')->clear('VAR');
// VAR is the varname to clear (unset)
// RETURNS TRUE (successfull) or FALSE (unsuccessfull)
Clear (unset) a namespace:
Data_Registry::init('NAMESPACE')->clearNameSpace();
// VAR is the varname to clear (unset)
// RETURNS TRUE (successfull) or FALSE (unsuccessfull)
Get a value from var and remove it (similar to flash data):
Data_Registry::init('NAMESPACE')->getFlash('VAR');
// Namespace can be any string;
// VAR is the varname to get from store
// RETURNS value or FALSE
Get a key from a varname stored and remove it:
Data_Registry::init('NAMESPACE')->getFlashKey('VAR','KEY');
// Namespace can be any string;
// VAR is the varname to store
// KEY is the varname index to store
// RETURNS value or FALSE
If global persistence is enabled, all namespaces are loaded automaticly,
but you can get a namespace from SESSION manualy, or override it at any moment:
Data_Registry::init('NAMESPACE')->restoreNameSpace();
// Namespace can be any string;
If global persistence is disabled, you can force to save a namespace:
Data_Registry::init('NAMESPACE')->backupNameSpace();
// Namespace can be any string;
Delete a SESSION namespace:
Data_Registry::init('NAMESPACE')->backupNameSpace(FALSE);
// Namespace can be any string;
Concatenate commands:
Data_Registry::init('NAMESPACE')->set('VAR','VALUE')->backupNameSpace();
Data_Registry::init('NAMESPACE')->set('VAR','VALUE')->setPersistence(TRUE)->backupNameSpace();
Data_Registry::init('NAMESPACE')->set('VAR1','VALUE1')->set('VAR2','VALUE2');
// Namespace can be any string;
Resusable classes:
Data_Registry::init('NAMESPACE')->getClass('Classname');
// Namespace can be any string;
// Returns the class pointer
Also, can use directlly objects inside a class:
Data_Registry::init('NAMESPACE')->getClass('Classname')->get('field');
// Namespace can be any string;
// All classes must to be included before dataStorage call, and if you want persistence with this class,
// class file must to be loaded before 'session_start()' command.
List vars stored
Data_Registry::init('NAMESPACE')->listVars();
// Namespace can be any string;
// Returns an array with information about the vars stored on current specified namespace
List all vars stored
Data_Registry::init()->listAllVars();
// Returns an array with information about the vars stored on all namespaces
Save a spacifc namespace for caching purpouses, all users can access it:
Data_Registry::init('FILECACHING')->set(md5("Data_Registry.php"),file_get_contents('Data_Registry.php'))->saveNameSpaceFile("/tmp/DRFiles");
Retrive a spacific namespace for caching purpouses:
Data_Registry::init('FILECACHING')->loadNameSpaceFile("/tmp/DRFiles")->get(md5("Data_Registry.php"));
|