Browse Source

Add debugInfo to a few classes that cause recursion

These objects often hold complicated cyclic references. This causes
something like debug($controller) to go horribly wrong. This removes the
most annoying cyclic references.
mark_story 11 years ago
parent
commit
ea917fe958
2 changed files with 27 additions and 0 deletions
  1. 15 0
      src/Event/EventManager.php
  2. 12 0
      src/Utility/ObjectRegistry.php

+ 15 - 0
src/Event/EventManager.php

@@ -320,4 +320,19 @@ class EventManager {
 		}
 		return $this->_listeners[$eventKey];
 	}
+
+/**
+ * Debug friendly object properties.
+ *
+ * @return array
+ */
+	public function __debugInfo() {
+		$properties = get_object_vars($this);
+		$properties['_generalManager'] = '(object) EventManager';
+		$properties['_listeners'] = [];
+		foreach ($this->_listeners as $key => $listeners) {
+			$properties['_listeners'][$key] = count($listeners) . ' listener(s)';
+		}
+		return $properties;
+	}
 }

+ 12 - 0
src/Utility/ObjectRegistry.php

@@ -221,4 +221,16 @@ abstract class ObjectRegistry {
 		unset($this->_loaded[$objectName]);
 	}
 
+/**
+ * Debug friendly object properties.
+ *
+ * @return array
+ */
+	public function __debugInfo() {
+		$properties = get_object_vars($this);
+		$properties['_loaded'] = array_keys($properties['_loaded']);
+		return $properties;
+	}
+
+
 }