Index: trunk/core/kernel/utility/debugger.php =================================================================== diff -u -N -r8402 -r8413 --- trunk/core/kernel/utility/debugger.php (.../debugger.php) (revision 8402) +++ trunk/core/kernel/utility/debugger.php (.../debugger.php) (revision 8413) @@ -325,7 +325,7 @@ if ($has_args) { // if parameter value is longer then 200 symbols, then leave only first 50 - $args = $this->highlightString($this->print_r($traceRec['args'], true, 50, 200)); + $args = $this->highlightString($this->print_r($traceRec['args'], true)); $ret .= ''; } $i++; @@ -409,26 +409,36 @@ * * @param Array $array * @param bool $return_output return output or print it out - * @param int $cut_first cut first N symbols, don't cut anything if -1 specified - * @package int $cut_min_length cut only of this length of string or greather + * @param int $tab_count offset in tabs * @return string */ - function print_r(&$array, $return_output = false, $cut_first = -1, $cut_min_length = -1) + function print_r(&$array, $return_output = false, $tab_count = -1) { - static $first_line = true, $tab_count = -1; + static $first_line = true; - if (is_null($array)) { - return 'NULL'; - } - elseif (!is_array($array)) { - if ($cut_min_length != -1 && strlen($array) > $cut_min_length) { - $array = substr($array, 0, $cut_first).' ...'; + // not an array at all + if (!is_array($array)) { + switch (gettype($array)) { + case 'NULL': + return 'NULL'."\n"; + break; + + case 'object': + return $this->processObject($array, $tab_count); + break; + + default: + // number or string + if (strlen($array) > 200) { + $array = substr($array, 0, 50).' ...'; + } + return $array."\n"; + break; } - return $array; } - + $output = ''; - + $tab_count++; $output .= "Array\n".str_repeat(' ', $tab_count)."(\n"; @@ -440,7 +450,7 @@ foreach ($array_keys as $key) { switch (gettype($array[$key])) { case 'array': - $output .= $tabsign.'['.$key.'] = '.$this->print_r($array[$key], true, 50, 200); + $output .= $tabsign.'['.$key.'] = '.$this->print_r($array[$key], true, $tab_count); break; case 'boolean': @@ -450,8 +460,8 @@ case 'integer': case 'double': case 'string': - if ($cut_min_length != -1 && strlen($array[$key]) > $cut_min_length) { - $array[$key] = substr($array[$key], 0, $cut_first).' ...'; + if (strlen($array[$key]) > 200) { + $array[$key] = substr($array[$key], 0, 50).' ...'; } $output .= $tabsign.'['.$key.'] = '.$array[$key]."\n"; break; @@ -461,42 +471,10 @@ break; case 'object': - $attribute_names = get_class_vars( get_class($array[$key]) ); - if (!$attribute_names) { - $output .= $tabsign.'['.$key."] = NO_ATTRIBUTES\n"; - } - else { - if ($this->IsBigObject($array[$key])) { - $output .= $tabsign.'['.$key.'] = SKIPPED (class: '.get_class($array[$key]).")\n"; - break; - } - - // $attribute_value - default value for this attribute, not used here - foreach ($attribute_names as $attribute_name => $attribute_value) { - if (is_object($array[$key]->$attribute_name)) { - // it is object - $object_class = get_class($array[$key]->$attribute_name); - if (!in_array($object_class, $this->RecursionStack)) { - // object [not in recursion stack] - if ($this->IsBigObject($array[$key]->$attribute_name)) { - $output .= $tabsign.'['.$attribute_name.'] = SKIPPED (class: '.$object_class.")\n"; - continue; - } - - array_push($this->RecursionStack, $object_class); - $output .= $this->print_r($array[$key]->$attribute_name, true, 50, 200); - array_pop($this->RecursionStack); - } - else { - // object [in recursion stack] - $output .= $tabsign.'['.$attribute_name.'] = *** RECURSION *** (class: '.$object_class.")\n"; - } - } - else { - $output .= $tabsign.'['.$attribute_name.'] = '.$this->print_r($array[$key]->$attribute_name, true, 50, 200)."\n"; - } - } - } + $output .= $tabsign.'['.$key."] = "; + $output .= "Object (".get_class($array[$key]).") = \n".str_repeat(' ', $tab_count + 1)."(\n"; + $output .= $this->processObject($array[$key], $tab_count + 2); + $output .= str_repeat(' ', $tab_count + 1).")\n"; break; default: @@ -506,7 +484,7 @@ } $tab_count--; - $output .= str_repeat(' ', $tab_count).")\n"; + $output .= str_repeat(' ', $tab_count).")\n"; if ($first_line) { $first_line = false; @@ -525,18 +503,40 @@ return true; } - /** - * Returns only first 200 chars of string, this allow to save amount of data sent to browser - * - * @param string $string - * @return string - */ - function cutStringForHTML($string) + function processObject(&$object, $tab_count) { - if (strlen($string) > 200) { - $string = substr($string,0,50).' ...'; + $object_class = get_class($object); + if (!in_array($object_class, $this->RecursionStack)) { + if ($this->IsBigObject($object)) { + return 'SKIPPED (class: '.$object_class.")\n"; + } + + $attribute_names = get_class_vars($object_class); + if (!$attribute_names) { + return "NO_ATTRIBUTES\n"; + } + else { + $output = ''; + array_push($this->RecursionStack, $object_class); + + $tabsign = $tab_count ? str_repeat(' ', $tab_count) : ''; + foreach ($attribute_names as $attribute_name => $attribute_value) { + if (is_object($object->$attribute_name)) { + // it is object + $output .= $tabsign.'['.$attribute_name.'] = '.$this->processObject($object->$attribute_name, $tab_count + 1); + } + else { + $output .= $tabsign.'['.$attribute_name.'] = '.$this->print_r($object->$attribute_name, true, $tab_count); + } + } + array_pop($this->RecursionStack); + return $output; + } } - return $string; + else { + // object [in recursion stack] + return '*** RECURSION *** (class: '.$object_class.")\n"; + } } /**