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) {
25 $Debugger =& Debugger
::instance();
26 return $Debugger->paint($mixed);
28 function paintIf($mixed, $conditional) {
29 $Debugger =& Debugger
::instance();
30 return $Debugger->paintIf($mixed, $conditional);
32 function paintWhen($mixed, $scopes = array()) {
33 $Debugger =& Debugger
::instance();
34 return $Debugger->paintWhen($mixed, $scopes);
36 function paintIfWhen($mixed, $conditional, $scopes = array()) {
37 $Debugger =& Debugger
::instance();
38 return $Debugger->paintIfWhen($mixed, $conditional, $scopes);
40 function addScope($id = false) {
41 $Debugger =& Debugger
::instance();
42 return $Debugger->addScope($id);
44 function removeScope($id) {
45 $Debugger =& Debugger
::instance();
46 return $Debugger->removeScope($id);
48 function resetScopes() {
49 $Debugger =& Debugger
::instance();
50 return $Debugger->resetScopes();
52 function isInScopes($array = array()) {
53 $Debugger =& Debugger
::instance();
54 return $Debugger->isInScopes($array);
60 * The debugging singleton. Most interesting stuff happens here.
65 public $shouldPaint = false;
67 public $current_scopes = array();
68 public $scope_nextID = 1;
69 public $add_pre = true;
71 public function Debugger() {
72 $this->add_pre
= !extension_loaded('xdebug');
75 public static function &instance() {
76 static $soleInstance = false;
77 if (!$soleInstance) $soleInstance = new Debugger();
81 public function paintIf($mixed, $conditional) {
82 if (!$conditional) return;
86 public function paintWhen($mixed, $scopes = array()) {
87 if (!$this->isInScopes($scopes)) return;
91 public function paintIfWhen($mixed, $conditional, $scopes = array()) {
92 if (!$conditional) return;
93 if (!$this->isInScopes($scopes)) return;
97 public function paint($mixed) {
99 if($this->add_pre
) echo '<pre>';
101 if($this->add_pre
) echo '</pre>';
104 public function addScope($id = false) {
106 $id = $this->scope_nextID++
;
108 $this->current_scopes
[$id] = true;
111 public function removeScope($id) {
112 if (isset($this->current_scopes
[$id])) unset($this->current_scopes
[$id]);
115 public function resetScopes() {
116 $this->current_scopes
= array();
117 $this->scope_nextID
= 1;
120 public function isInScopes($scopes = array()) {
121 if (empty($this->current_scopes
)) {
124 if (!is_array($scopes)) {
125 $scopes = array($scopes);
127 foreach ($scopes as $scope_id) {
128 if (empty($this->current_scopes
[$scope_id])) {
132 if (empty($scopes)) {
133 if ($this->scope_nextID
== 1) {
136 for($i = 1; $i < $this->scope_nextID
; $i++
) {
137 if (empty($this->current_scopes
[$i])) {