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

This will only work in PHP >= 5.3. Patch originally created
by 'dereuromark'.
This commit is contained in:
mark_story 2012-08-06 13:31:35 -04:00
parent 8931b74ba2
commit 57c495f53a
2 changed files with 60 additions and 0 deletions

View file

@ -325,8 +325,43 @@ object(View) {
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(

View file

@ -576,6 +576,31 @@ class Debugger {
$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 .= '}';