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
6 namespace Magento\Framework;
7 
18 class Registry
19 {
25  private $_registry = [];
26 
35  public function registry($key)
36  {
37  if (isset($this->_registry[$key])) {
38  return $this->_registry[$key];
39  }
40  return null;
41  }
42 
54  public function register($key, $value, $graceful = false)
55  {
56  if (isset($this->_registry[$key])) {
57  if ($graceful) {
58  return;
59  }
60  throw new \RuntimeException('Registry key "' . $key . '" already exists');
61  }
62  $this->_registry[$key] = $value;
63  }
64 
73  public function unregister($key)
74  {
75  if (isset($this->_registry[$key])) {
76  if (is_object($this->_registry[$key])
77  && method_exists($this->_registry[$key], '__destruct')
78  && is_callable([$this->_registry[$key], '__destruct'])
79  ) {
80  $this->_registry[$key]->__destruct();
81  }
82  unset($this->_registry[$key]);
83  }
84  }
85 
89  public function __destruct()
90  {
91  $keys = array_keys($this->_registry);
92  array_walk($keys, [$this, 'unregister']);
93  }
94 }
$value
Definition: gender.phtml:16