94 if (!self::$_instance) {
95 self::$_instance =
new self();
107 public function load($idx, $default =
null)
109 if (isset($this->_references[$idx])) {
110 $idx = $this->_references[$idx];
112 if (isset($this->_objects[$idx])) {
113 return $this->_objects[$idx];
129 public function save($object, $idx =
null, $tags =
null)
132 if (!is_object($object)) {
136 $hash = spl_object_hash($object);
137 if ($idx !==
null && strpos($idx,
'{') !==
false) {
138 $idx = str_replace(
'{hash}', $hash, $idx);
140 if (isset($this->_hashes[$hash])) {
143 $this->_references[$idx] = $this->_hashes[$hash];
145 return $this->_hashes[$hash];
152 if (isset($this->_objects[$idx])) {
153 throw new \Magento\Framework\Exception\LocalizedException(
155 'Object already exists in registry (%1). Old object class: %2, new object class: %3',
156 [$idx, get_class($this->_objects[$idx]), get_class($object)]
161 $this->_objects[$idx] = $object;
163 $this->_hashes[$hash] = $idx;
164 $this->_objectHashes[$idx] = $hash;
166 if (is_string($tags)) {
167 $this->_tags[$tags][$idx] =
true;
168 $this->_objectTags[$idx][$tags] =
true;
169 }
elseif (is_array($tags)) {
170 foreach ($tags as $t) {
171 $this->_tags[$t][$idx] =
true;
172 $this->_objectTags[$idx][$t] =
true;
190 if (is_array($refName)) {
191 foreach ($refName as $ref) {
197 if (isset($this->_references[$refName])) {
198 throw new \Magento\Framework\Exception\LocalizedException(
200 'The reference already exists: %1. New index: %2, old index: %3',
201 [$refName, $idx, $this->_references[$refName]]
205 $this->_references[$refName] = $idx;
206 $this->_objectReferences[$idx][$refName] =
true;
217 public function delete($idx)
220 if (is_object($idx)) {
221 $idx = $this->
find($idx);
222 if (
false === $idx) {
226 unset($this->_objects[$idx]);
229 }
elseif (!isset($this->_objects[$idx])) {
234 unset($this->_objects[$idx]);
236 unset($this->_hashes[$this->_objectHashes[$idx]], $this->_objectHashes[$idx]);
238 if (isset($this->_objectTags[$idx])) {
239 foreach ($this->_objectTags[$idx] as $t => $dummy) {
240 unset($this->_tags[$t][$idx]);
242 unset($this->_objectTags[$idx]);
245 if (isset($this->_objectReferences[$idx])) {
246 foreach ($this->_references as $r => $dummy) {
247 unset($this->_references[$r]);
249 unset($this->_objectReferences[$idx]);
264 foreach ($this->_objects as $idx => $object) {
265 if ($object instanceof
$class) {
280 if (is_string($tags)) {
283 foreach ($tags as $t) {
284 foreach ($this->_tags[$t] as $idx => $dummy) {
299 return isset($this->_objects[$idx]) || isset($this->_references[$idx]);
310 foreach ($this->_objects as $idx => $obj) {
311 if ($object === $obj) {
327 foreach ($this->_objects as $idx => $obj) {
328 if (in_array($idx, $ids)) {
329 $objects[$idx] = $obj;
343 return isset($this->_hashes[$hash]) ? $this->_objects[$this->_hashes[$hash]] :
null;
355 if (is_string($tags)) {
359 foreach ($tags as $t) {
360 foreach ($this->_tags[$t] as $idx => $dummy) {
361 if (isset($objects[$idx])) {
364 $objects[$idx] = $this->
load($idx);
379 foreach ($this->_objects as $idx => $object) {
380 if ($object instanceof
$class) {
381 $objects[$idx] = $object;
395 public function debug($idx, $object =
null)
397 $bt = debug_backtrace();
399 foreach ($bt as
$i => $step) {
401 'file' => isset($step[
'file']) ? $step[
'file'] :
null,
402 'line' => isset($step[
'line']) ? $step[
'line'] :
null,
403 'function' => isset($step[
'function']) ? $step[
'function'] :
null,
406 $this->_debug[$idx] =
$debug;
417 if (is_string($ids)) {
421 foreach ($ids as $idx) {
422 $debug[$idx] = $this->_debug[$idx];
elseif(isset( $params[ 'redirect_parent']))
load($idx, $default=null)
save($object, $idx=null, $tags=null)
reference($refName, $idx)
debug($idx, $object=null)
$_option $_optionId $class