Registry Package provides a fluent, object-oriented interface for storing data globally in a well managed fashion, helping to prevent global meltdown.

Installation

With Composer

composer require glowy/registry

Usage

use Glowy\Registry\Registry;

// Using public static method getInstance()
$registry = Registry::getInstance();

// Using global helper function registry() thats returns Registry::getInstance()
$registry = registry();

Extending

Registry are "macroable", which allows you to add additional methods to the Registry class at run time. For example, the following code adds a customMethod method to the Registry class:

use Glowy\Registry\Registry;
use Glowy\Macroable\Macroable;

Registry::getInstance()->set('foo', 'bar');

Registry::macro('customMethod', function() {
    return $this->count();
});

echo Registry::getInstance()->customMethod();

The above example will output:

1

Registry Package is extending Arrays Package. All methods of Arrays Package are available when using Registry Package in your projects for manipulations with Registry.

Examples

use Glowy\Registry\Registry;

$registry = Registry::getInstance();

$registry->set('foo', 'bar');
$registry->set('bar', 'foo');

echo $registry->count();

The above example will output:

2

Methods

getInstance Gets the Registry instance via lazy initialization (created on first usage).