PHP Registry Class

This class implements one pattern of the object-oriented programming. It’s called Singleton-pattern. You can use it as a global container for your application. It acts like a global array, that stores variables, objects and arrays for you – and it is avaible everywhere in your application. This pattern is as simple as it is powerful.

download: latest version (1.0.0)


init()

desc

This function initialize the Registry for use. You can also call it, if you want to reset the Registry (remove all objects).

param

  • No params

return

void


set($key, $value)

desc

adds or updates the $value with the $key

param

  • $key – the key in the array
  • $value – value of $key in the array

return

boolean – true on success, false on failure


get($key)

desc

returns the value of $key from the array

param

  • $key – element to return

return

the element (by reference) on success, false on failure


exists($key)

desc

it tests, whether the key exists or not

param

  • $key – key of the required element

return

boolean – true on success, false on failure


remove($key)

desc

removes an element from the array

param

  • $key – key to remove

return

void


count()

desc

returns the number of elements in the array

param

  • no params

return

integer – number of elements


Examples

Registry::init();
/* init e.g. a database connection -> $conn */
Registry::add('db',$conn);
/* do something other operations or jump */
/*into another function */
Registry::get('db')->q("SELECT.........");
/* or */
$conn = Registry::get('db');
/* continue working */