Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Registry.php
Go to the documentation of this file.
1 <?php
30 class Zend_Registry extends ArrayObject
31 {
36  private static $_registryClassName = 'Zend_Registry';
37 
42  private static $_registry = null;
43 
49  public static function getInstance()
50  {
51  if (self::$_registry === null) {
52  self::init();
53  }
54 
55  return self::$_registry;
56  }
57 
66  public static function setInstance(Zend_Registry $registry)
67  {
68  if (self::$_registry !== null) {
69  #require_once 'Zend/Exception.php';
70  throw new Zend_Exception('Registry is already initialized');
71  }
72 
73  self::setClassName(get_class($registry));
74  self::$_registry = $registry;
75  }
76 
82  protected static function init()
83  {
84  self::setInstance(new self::$_registryClassName());
85  }
86 
97  public static function setClassName($registryClassName = 'Zend_Registry')
98  {
99  if (self::$_registry !== null) {
100  #require_once 'Zend/Exception.php';
101  throw new Zend_Exception('Registry is already initialized');
102  }
103 
104  if (!is_string($registryClassName)) {
105  #require_once 'Zend/Exception.php';
106  throw new Zend_Exception("Argument is not a class name");
107  }
108 
112  if (!class_exists($registryClassName)) {
113  #require_once 'Zend/Loader.php';
114  Zend_Loader::loadClass($registryClassName);
115  }
116 
117  self::$_registryClassName = $registryClassName;
118  }
119 
125  public static function _unsetInstance()
126  {
127  self::$_registry = null;
128  }
129 
141  public static function get($index)
142  {
143  $instance = self::getInstance();
144 
145  if (!$instance->offsetExists($index)) {
146  #require_once 'Zend/Exception.php';
147  throw new Zend_Exception("No entry is registered for key '$index'");
148  }
149 
150  return $instance->offsetGet($index);
151  }
152 
165  public static function set($index, $value)
166  {
167  $instance = self::getInstance();
168  $instance->offsetSet($index, $value);
169  }
170 
178  public static function isRegistered($index)
179  {
180  if (self::$_registry === null) {
181  return false;
182  }
183  return self::$_registry->offsetExists($index);
184  }
185 
193  public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS)
194  {
195  parent::__construct($array, $flags);
196  }
197 
204  public function offsetExists($index)
205  {
206  return array_key_exists($index, $this);
207  }
208 
209 }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
offsetExists($index)
Definition: Registry.php:204
static setInstance(Zend_Registry $registry)
Definition: Registry.php:66
static _unsetInstance()
Definition: Registry.php:125
__construct($array=array(), $flags=parent::ARRAY_AS_PROPS)
Definition: Registry.php:193
static isRegistered($index)
Definition: Registry.php:178
$value
Definition: gender.phtml:16
static getInstance()
Definition: Registry.php:49
static init()
Definition: Registry.php:82
static setClassName($registryClassName='Zend_Registry')
Definition: Registry.php:97
$index
Definition: list.phtml:44