Fandom

Wikia Developers Wiki

Nirvana/WikiaRegistry

< Nirvana

915pages on
this wiki
Add New Page
Talk0 Share

WikiaRegistry provides convinient, abstract way of storing shared data. It behaves as hash map allowing storage, retrieval, removal and testing of key => value data while abstracting data storage. In Wikia it's being used to abstract global variables access (WikiaGlobalsRegistry) and application/extensions specific data (WikiaLocalRegistry).

Object oriented data access

Storing data with WikiaRegistry is simple. Just create an instance of concrete WikiaRegistry class and call it's set method:

$registry = new WikiaLocalRegistry();
$registry->set('myKey', 'myData');

Later on data can be retrieved using has() and get() methods:

if ($registry->has('myKey')) {
    echo $registry->get('myKey');
}

No longer needed data can be removed from registry using remove() method:

$registry->remove('myKey');

Array access

WikiaRegistry implements ArrayAccess interface, thus it can be used as array too:

$registry = new WikiaLocalRegistry();
$registry['myKey'] = 'myData';

if (isset($registry['myKey']) {
    echo $registry['myKey'];
    unset($registry['myKey'];
}

Advantages

Real advantage over using plain arrays or global variables is ability to simulate registry (mock it). When testing one can force registry to return some specific data, for instance Memcache mock instead of real Memcache object.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.