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
18 * DEPRECATE AND REMOVE ALL CALLS!
22 * Convenience global functions. Corresponds to method on Debugger.
24 function paint($mixed)
26 $Debugger =& Debugger
::instance();
27 return $Debugger->paint($mixed);
29 function paintIf($mixed, $conditional)
31 $Debugger =& Debugger
::instance();
32 return $Debugger->paintIf($mixed, $conditional);
34 function paintWhen($mixed, $scopes = array())
36 $Debugger =& Debugger
::instance();
37 return $Debugger->paintWhen($mixed, $scopes);
39 function paintIfWhen($mixed, $conditional, $scopes = array())
41 $Debugger =& Debugger
::instance();
42 return $Debugger->paintIfWhen($mixed, $conditional, $scopes);
44 function addScope($id = false)
46 $Debugger =& Debugger
::instance();
47 return $Debugger->addScope($id);
49 function removeScope($id)
51 $Debugger =& Debugger
::instance();
52 return $Debugger->removeScope($id);
54 function resetScopes()
56 $Debugger =& Debugger
::instance();
57 return $Debugger->resetScopes();
59 function isInScopes($array = array())
61 $Debugger =& Debugger
::instance();
62 return $Debugger->isInScopes($array);
68 * The debugging singleton. Most interesting stuff happens here.
73 public $shouldPaint = false;
75 public $current_scopes = array();
76 public $scope_nextID = 1;
77 public $add_pre = true;
79 public function __construct()
81 $this->add_pre
= !extension_loaded('xdebug');
84 public static function &instance() {
85 static $soleInstance = false;
86 if (!$soleInstance) $soleInstance = new Debugger();
90 public function paintIf($mixed, $conditional)
92 if (!$conditional) return;
96 public function paintWhen($mixed, $scopes = array())
98 if (!$this->isInScopes($scopes)) return;
102 public function paintIfWhen($mixed, $conditional, $scopes = array())
104 if (!$conditional) return;
105 if (!$this->isInScopes($scopes)) return;
106 $this->paint($mixed);
109 public function paint($mixed)
112 if($this->add_pre
) echo '<pre>';
114 if($this->add_pre
) echo '</pre>';
117 public function addScope($id = false)
120 $id = $this->scope_nextID++
;
122 $this->current_scopes
[$id] = true;
125 public function removeScope($id)
127 if (isset($this->current_scopes
[$id])) unset($this->current_scopes
[$id]);
130 public function resetScopes()
132 $this->current_scopes
= array();
133 $this->scope_nextID
= 1;
136 public function isInScopes($scopes = array())
138 if (empty($this->current_scopes
)) {
141 if (!is_array($scopes)) {
142 $scopes = array($scopes);
144 foreach ($scopes as $scope_id) {
145 if (empty($this->current_scopes
[$scope_id])) {
149 if (empty($scopes)) {
150 if ($this->scope_nextID
== 1) {
153 for($i = 1; $i < $this->scope_nextID
; $i++
) {
154 if (empty($this->current_scopes
[$i])) {
164 // vim: et sw=4 sts=4