Skip to content
Permalink
Browse files

Enabled Debugger::exportVar() to display private & protected properties.

This will only work in PHP >= 5.3. Patch originally created
by 'dereuromark'.
  • Loading branch information...
markstory committed Aug 6, 2012
1 parent 8931b74 commit 57c495f53a63b92fe2766f03d6f20754f79be31d
Showing with 60 additions and 0 deletions.
  1. +35 −0 lib/Cake/Test/Case/Utility/DebuggerTest.php
  2. +25 −0 lib/Cake/Utility/Debugger.php
@@ -325,8 +325,43 @@ public function testExportVar() {
elementCacheSettings => array()
int => (int) 2
float => (float) 1.333
TEXT;
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$expected .= <<<TEXT
[protected] _passedVars => array(
(int) 0 => 'viewVars',
(int) 1 => 'autoLayout',
(int) 2 => 'ext',
(int) 3 => 'helpers',
(int) 4 => 'view',
(int) 5 => 'layout',
(int) 6 => 'name',
(int) 7 => 'theme',
(int) 8 => 'layoutPath',
(int) 9 => 'viewPath',
(int) 10 => 'request',
(int) 11 => 'plugin',
(int) 12 => 'passedArgs',
(int) 13 => 'cacheAction'
)
[protected] _scripts => array()
[protected] _paths => array()
[protected] _helpersLoaded => false
[protected] _parents => array()
[protected] _current => null
[protected] _currentType => ''
[protected] _stack => array()
[protected] _eventManager => object(CakeEventManager) {}
[protected] _eventManagerConfigured => false
[private] __viewFileName => null
TEXT;
}
$expected .= <<<TEXT
}
TEXT;
$this->assertTextEquals($expected, $result);
$data = array(
@@ -576,6 +576,31 @@ protected static function _object($var, $depth, $indent) {
$value = self::_export($value, $depth - 1, $indent);
$props[] = "$key => " . $value;
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$ref = new ReflectionObject($var);
$reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PROTECTED);
foreach ($reflectionProperties as $reflectionProperty) {
$reflectionProperty->setAccessible(true);
$property = $reflectionProperty->getValue($var);
$value = self::_export($property, $depth - 1, $indent);
$key = $reflectionProperty->name;
$props[] = "[protected] $key => " . $value;
}
$reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PRIVATE);
foreach ($reflectionProperties as $reflectionProperty) {
$reflectionProperty->setAccessible(true);
$property = $reflectionProperty->getValue($var);
$value = self::_export($property, $depth - 1, $indent);
$key = $reflectionProperty->name;
$props[] = "[private] $key => " . $value;
}
}
$out .= $break . implode($break, $props) . $end;
}
$out .= '}';

0 comments on commit 57c495f

Please sign in to comment.
You can’t perform that action at this time.