6 * This file gives a developer a set of tools useful for performing code
7 * consistency checks. This includes scoping code blocks to ensure that
8 * only the interesting iteration of a loop gets outputted, a paint()
9 * function that acts like var_dump() with pre tags, and conditional
15 * Integrate into SimpleTest so it tells us whether or not there were any
16 not cleaned up debug calls.
17 * Custom var_dump() that ignores blacklisted properties
21 * Convenience global functions. Corresponds to method on Debugger.
23 function paint($mixed) {
24 $Debugger =& Debugger
::instance();
25 return $Debugger->paint($mixed);
27 function paintIf($mixed, $conditional) {
28 $Debugger =& Debugger
::instance();
29 return $Debugger->paintIf($mixed, $conditional);
31 function paintWhen($mixed, $scopes = array()) {
32 $Debugger =& Debugger
::instance();
33 return $Debugger->paintWhen($mixed, $scopes);
35 function paintIfWhen($mixed, $conditional, $scopes = array()) {
36 $Debugger =& Debugger
::instance();
37 return $Debugger->paintIfWhen($mixed, $conditional, $scopes);
39 function addScope($id = false) {
40 $Debugger =& Debugger
::instance();
41 return $Debugger->addScope($id);
43 function removeScope($id) {
44 $Debugger =& Debugger
::instance();
45 return $Debugger->removeScope($id);
47 function resetScopes() {
48 $Debugger =& Debugger
::instance();
49 return $Debugger->resetScopes();
51 function isInScopes($array = array()) {
52 $Debugger =& Debugger
::instance();
53 return $Debugger->isInScopes($array);
58 * The debugging singleton. Most interesting stuff happens here.
63 var $shouldPaint = false;
65 var $current_scopes = array();
66 var $scope_nextID = 1;
70 $this->add_pre
= !extension_loaded('xdebug');
73 function &instance() {
74 static $soleInstance = false;
75 if (!$soleInstance) $soleInstance = new Debugger();
79 function paintIf($mixed, $conditional) {
80 if (!$conditional) return;
84 function paintWhen($mixed, $scopes = array()) {
85 if (!$this->isInScopes($scopes)) return;
89 function paintIfWhen($mixed, $conditional, $scopes = array()) {
90 if (!$conditional) return;
91 if (!$this->isInScopes($scopes)) return;
95 function paint($mixed) {
97 if($this->add_pre
) echo '<pre>';
99 if($this->add_pre
) echo '</pre>';
102 function addScope($id = false) {
104 $id = $this->scope_nextID++
;
106 $this->current_scopes
[$id] = true;
109 function removeScope($id) {
110 if (isset($this->current_scopes
[$id])) unset($this->current_scopes
[$id]);
113 function resetScopes() {
114 $this->current_scopes
= array();
115 $this->scope_nextID
= 1;
118 function isInScopes($scopes = array()) {
119 if (empty($this->current_scopes
)) {
122 if (!is_array($scopes)) {
123 $scopes = array($scopes);
125 foreach ($scopes as $scope_id) {
126 if (empty($this->current_scopes
[$scope_id])) {
130 if (empty($scopes)) {
131 if ($this->scope_nextID
== 1) {
134 for($i = 1; $i < $this->scope_nextID
; $i++
) {
135 if (empty($this->current_scopes
[$i])) {