Online Merchant v2.4 Joli

Registry OSC\OM\Registry

Introduction

The registry is an object storage container strictly used to store object instances and access them by reference. It does not allow registered objects to be overwritten unless manually specified to do so.

Adding to the Registry

Objects can be added to the registry using Registry::set().

use OSC\OM\Db;
use OSC\OM\Registry;

$OSCOM_Db = Db::initialize();

Registry::set('Db', $OSCOM_Db);

Parameters

Registry::set($key, $value, $force)
Parameter Value
$key The name of the object to reference in the registry.
$value The object to store in the registry.
$force If this is enabled, overwrite an existing object with a new value. Default: false

Accessing the Registry

An object can be accessed in the registry using Registry::get().

use OSC\OM\Registry;

$OSCOM_Db = Registry::get('Db');

Parameters

Registry::get($key)
Parameter Value
$key The name of the object to access in the registry.

Checking the Registry

An existing object can be checked for in the registry using Registry::exists().

use OSC\OM\Db;
use OSC\OM\Registry;

if (Registry::exists('Db')) {
	$OSCOM_Db = Registry::get('Db');
} else {
	$OSCOM_Db = Db::initialize();

	Registry::set('Db', $OSCOM_Db);
}

Parameters

Registry::exists($key)
Parameter Value
$key The name of the object to check in the registry for.