Jump to content

Recommended Posts

Registry ClicShopping\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 ClicShopping\OM\Db;
use ClicShopping\OM\Registry;

$CLICSHOPPING_Db = Db::initialize();

Registry::set('Db', $CLICSHOPPING_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 ClicShopping\OM\Registry;

$CLICSHOPPING_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 ClicShopping\OM\Db;
use ClicShopping\OM\Registry;

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

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

Parameters

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

 

Link to post
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use