浏览代码

added DBG::niceDump

Piotr Labudda 8 年之前
父节点
当前提交
37bd235e77
共有 1 个文件被更改,包括 30 次插入0 次删除
  1. 30 0
      SE/se-lib/DBG.php

+ 30 - 0
SE/se-lib/DBG.php

@@ -250,6 +250,36 @@ class DBG {
 		]) . "\n";
 		]) . "\n";
 	}
 	}
 
 
+	public static function niceDump($variable, $varName, $params = []) {
+		$col = ['green'=>'#96c178', 'red'=>'#de6b74', 'blue'=>'#55b5c1', 'bg-dark'=>'#282c34', 'white'=>'#abb2bf', 'orange'=>'#d19a66', 'violet'=>'#c476db'];
+		$maxHeight = V::get('maxHeight', '400px', $params);
+		ob_start();
+		var_dump($variable);
+		$cnt = ob_get_clean();
+		$cnt = preg_replace('/=>\s+/', ' => ', $cnt);
+		$cnt = preg_replace('/\) "(.*)/', ') <span style="color:'.$col['orange'].'">"\1</span>', $cnt);
+		$cnt = preg_replace('/\["(\w+)"\] =>/', '[<span style="color:'.$col['green'].'">\1</span>] =>', $cnt);
+		$cnt = preg_replace('/object\((\w+)\)/', '<span style="color:'.$col['blue'].'">object(<span style="color:'.$col['orange'].'">\1</span>)</span>', $cnt);
+		$cnt = preg_replace('/string\((\w+)\)/', '<span style="color:'.$col['blue'].'">string(<span style="color:'.$col['orange'].'">\1</span>)</span>', $cnt);
+		$cnt = preg_replace('/array\((\w+)\)/', '<span style="color:'.$col['blue'].'">array(<span style="color:'.$col['orange'].'">\1</span>)</span>', $cnt);
+		$cnt = preg_replace('/int\((\w+)\)/', '<span style="color:'.$col['blue'].'">int(<span style="color:'.$col['orange'].'">\1</span>)</span>', $cnt);
+		$cnt = preg_replace('/bool\((\w+)\)/', '<span style="color:'.$col['blue'].'">bool(<span style="color:'.$col['orange'].'">\1</span>)</span>', $cnt);
+		echo UI::h('details', ['style'=>"max-width:800px"], [
+			UI::h('summary', ['style'=>"padding:3px 8px;border:1px solid #ccc;background-color:{$col['bg-dark']};color:{$col['white']};font-size:small"],
+				'<b style="color:'.$col['red'].'">' . $varName . "</b>:"
+			),
+			UI::h('pre', [
+				'style' => implode(";", [
+					'background-color:'.$col['bg-dark'],
+					'color:'.$col['white'],
+					'border:1px solid #ccc;border-radius:0',
+					'font-size:x-small',
+					($maxHeight) ? "max-height:{$maxHeight};overflow:scroll" : ''
+				])
+			], $cnt)
+		]) . "\n";
+	}
+
 	/**
 	/**
 	 * @param $mixedArg string or Exception
 	 * @param $mixedArg string or Exception
 	 */
 	 */