From fadbe60cb25afb17777d5180e41ad7593fa25b97 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 17 Jan 2023 20:09:06 +0100 Subject: better location for backslash removal; omit faulty blanks around class body --- it_debug.class | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/it_debug.class b/it_debug.class index c1ee8e1..766a82f 100644 --- a/it_debug.class +++ b/it_debug.class @@ -170,17 +170,17 @@ static function dump($args, $p = []) $var = array_shift($argnames); $item = gettype($arg) == 'resource' || is_array($arg) && isset($arg['GLOBALS']) || is_object($arg) && is_a($arg, "SimpleXMLElement") ? trim(print_r($arg, true)) : trim(var_export($arg, true)); - # Replace PHP 5 var_export object representation by old style + # Replace PHP 5+ var_export object representation by old readable style while (preg_match("#(.*\b)(\w+)::__set_state\(array\(([^()]+)\)\)(.*)#s", $item, $regs) && ++$iterations < 100) { list (, $head, $classname, $values, $tail) = $regs; $classname = strtolower($classname); $values = preg_replace("#'(\w+)' =>\s*([^\n]+),#", 'var \$$1 = $2;', $values); - $item = $head . "class $classname { $values }$tail"; + $item = rtrim($head, '\\') . "class $classname {" . $values . "}" . $tail; } $item = preg_replace_callback('/\b(1[2-9]\d\d\d\d\d\d\d\d)\b(.*)/', function($m) { return $m[1] . $m[2] . " # " . date('Y-m-d H:i:s', $m[1]); }, $item); - $item = preg_replace("#(=>?)\s*\n\s*\\\?(array|class|\w+::)#", '$1 $2', $item); # array( and class on same line as key + $item = preg_replace("#(=>?)\s*\n\s*(array|class)#", '$1 $2', $item); # array( and class on same line as key $item = preg_replace_callback('#array \(\s+([^(){};]{1,100}),\s+\)#', function($m) { return "array (" . preg_replace("#\n\s+#", " ", $m[1]) . ")"; }, $item); # short arrays on 1 line $item = preg_replace('#class (\S+) \{\s+([^({,;]+;)?\s+\}#', 'class $1 { $2 }', $item); # 1-element objects on 1 line #$item = preg_replace('#\{\s*var \$attr#', '{ var $attr', $item); # move $attr on same line -- cgit v1.2.3