25 private $_registry = [];
37 if (isset($this->_registry[$key])) {
38 return $this->_registry[$key];
54 public function register($key,
$value, $graceful =
false)
56 if (isset($this->_registry[$key])) {
60 throw new \RuntimeException(
'Registry key "' . $key .
'" already exists');
62 $this->_registry[$key] =
$value;
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'])
80 $this->_registry[$key]->__destruct();
82 unset($this->_registry[$key]);
91 $keys = array_keys($this->_registry);
92 array_walk($keys, [$this,
'unregister']);