14
14
*/
15
15
namespace Cake \Error ;
16
16
17
+ use Cake \Core \InstanceConfigTrait ;
17
18
use Cake \Log \Log ;
18
19
use Cake \Utility \Hash ;
19
20
use Cake \Utility \Security ;
32
33
*/
33
34
class Debugger
34
35
{
36
+ use InstanceConfigTrait;
37
+
38
+ /**
39
+ * Default configuration
40
+ *
41
+ * @var array
42
+ */
43
+ protected $ _defaultConfig = [
44
+ 'mask ' => []
45
+ ];
35
46
36
47
/**
37
48
* A list of errors generated by the application.
@@ -152,7 +163,7 @@ public function __construct()
152
163
* Returns a reference to the Debugger singleton object instance.
153
164
*
154
165
* @param string|null $class Class name.
155
- * @return object
166
+ * @return object|Debugger
156
167
*/
157
168
public static function getInstance ($ class = null )
158
169
{
@@ -169,6 +180,24 @@ public static function getInstance($class = null)
169
180
return $ instance [0 ];
170
181
}
171
182
183
+ /**
184
+ * Read or write configuration options for the Debugger instance.
185
+ *
186
+ * @param string|array|null $key The key to get/set, or a complete array of configs.
187
+ * @param mixed|null $value The value to set.
188
+ * @param bool $merge Whether to recursively merge or overwrite existing config, defaults to true.
189
+ * @return mixed Config value being read, or the object itself on write operations.
190
+ * @throws \Cake\Core\Exception\Exception When trying to set a key that is invalid.
191
+ */
192
+ public static function configInstance ($ key = null , $ value = null , $ merge = true )
193
+ {
194
+ if (is_array ($ key ) || func_num_args () >= 2 ) {
195
+ return static ::getInstance ()->config ($ key , $ value , $ merge );
196
+ }
197
+
198
+ return static ::getInstance ()->config ($ key );
199
+ }
200
+
172
201
/**
173
202
* Recursively formats and outputs the contents of the supplied variable.
174
203
*
@@ -505,10 +534,13 @@ protected static function _array(array $var, $depth, $indent)
505
534
$ vars = [];
506
535
507
536
if ($ depth >= 0 ) {
537
+ $ mask = (array )static ::configInstance ('mask ' );
508
538
foreach ($ var as $ key => $ val ) {
509
539
// Sniff for globals as !== explodes in < 5.4
510
540
if ($ key === 'GLOBALS ' && is_array ($ val ) && isset ($ val ['GLOBALS ' ])) {
511
541
$ val = '[recursion] ' ;
542
+ } elseif (array_key_exists ($ key , $ mask )) {
543
+ $ val = (string )$ mask [$ key ];
512
544
} elseif ($ val !== $ var ) {
513
545
$ val = static ::_export ($ val , $ depth , $ indent );
514
546
}
@@ -555,9 +587,10 @@ protected static function _object($var, $depth, $indent)
555
587
}
556
588
557
589
if ($ depth > 0 ) {
590
+ $ mask = (array )static ::configInstance ('mask ' );
558
591
$ objectVars = get_object_vars ($ var );
559
592
foreach ($ objectVars as $ key => $ value ) {
560
- $ value = static ::_export ($ value , $ depth - 1 , $ indent );
593
+ $ value = array_key_exists ( $ key , $ mask ) ? $ mask [ $ key ] : static ::_export ($ value , $ depth - 1 , $ indent );
561
594
$ props [] = "$ key => " . $ value ;
562
595
}
563
596
@@ -575,7 +608,12 @@ protected static function _object($var, $depth, $indent)
575
608
576
609
$ value = static ::_export ($ property , $ depth - 1 , $ indent );
577
610
$ key = $ reflectionProperty ->name ;
578
- $ props [] = sprintf ('[%s] %s => %s ' , $ visibility , $ key , $ value );
611
+ $ props [] = sprintf (
612
+ '[%s] %s => %s ' ,
613
+ $ visibility ,
614
+ $ key ,
615
+ array_key_exists ($ key , $ mask ) ? $ mask [$ key ] : $ value
616
+ );
579
617
}
580
618
}
581
619
0 commit comments