strings, booleans and integers rendering improved some fixes in objects, arrays and resources rendering tests updated some docs added added doxyfile
This commit is contained in:
parent
4948b40ef5
commit
be6014ee4b
3 changed files with 2120 additions and 177 deletions
1803
dBug.doxyfile
Normal file
1803
dBug.doxyfile
Normal file
File diff suppressed because it is too large
Load diff
479
dBug.php
479
dBug.php
|
@ -21,6 +21,10 @@
|
|||
*
|
||||
\*********************************************************************************************************************/
|
||||
|
||||
/*!
|
||||
@author ospinto
|
||||
@author KOLANICH
|
||||
*/
|
||||
class dBug {
|
||||
|
||||
var $xmlDepth=array();
|
||||
|
@ -30,19 +34,26 @@ class dBug {
|
|||
var $xmlCount=0;
|
||||
var $xmlAttrib;
|
||||
var $xmlName;
|
||||
var $arrType=array("array","object","resource","boolean","NULL");
|
||||
//var $arrType=array("array",'object',"resource","boolean","NULL");
|
||||
|
||||
//!shows wheither the main header for this dBug call was drawn
|
||||
var $bInitialized = false;
|
||||
var $bCollapsed = false;
|
||||
var $arrHistory = array();
|
||||
static $embeddedStringMaxLength=50;
|
||||
|
||||
//constructor
|
||||
/*!
|
||||
@param mixed $var Variable to dump
|
||||
@param string $forceType type to marshall $var to show
|
||||
@param boolean $bCollapsed should output be collapsed
|
||||
*/
|
||||
function dBug($var,$forceType="",$bCollapsed=false) {
|
||||
//include js and css scripts
|
||||
if(!defined('BDBUGINIT')) {
|
||||
define("BDBUGINIT", TRUE);
|
||||
$this->initJSandCSS();
|
||||
define('BDBUGINIT', TRUE);
|
||||
self::initJSandCSS();
|
||||
}
|
||||
$arrAccept=array("array","object","xml"); //array of variable types that can be "forced"
|
||||
$arrAccept=array("array",'object',"xml"); //array of variable types that can be "forced"
|
||||
$this->bCollapsed = $bCollapsed;
|
||||
if(in_array($forceType,$arrAccept))
|
||||
$this->{"varIs".ucfirst($forceType)}($var);
|
||||
|
@ -81,21 +92,68 @@ class dBug {
|
|||
return "";
|
||||
}
|
||||
|
||||
//create the main table header
|
||||
function makeTableHeader($type,$header,$colspan=2) {
|
||||
function initializeHeader(&$header){
|
||||
if(!$this->bInitialized) {
|
||||
$header = $this->getVariableName() . " (" . $header . ")";
|
||||
$this->bInitialized = true;
|
||||
}
|
||||
$str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : "";
|
||||
|
||||
echo "<table cellspacing=2 cellpadding=3 class=\"dBug_".$type."\">
|
||||
<tr>
|
||||
<td ".$str_i."class=\"dBug_".$type."Header\" colspan=".$colspan." onClick='dBug_toggleTable(this)'>".$header."</td>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
//create the table row header
|
||||
/*!
|
||||
@name rendering functions
|
||||
used to make tables representing different variables
|
||||
*/
|
||||
//!@{
|
||||
|
||||
//!creates the main table header
|
||||
/*!
|
||||
@param string $type name of the style of the header cell
|
||||
@param string $header the text of the header cell
|
||||
@param integer $colspan colspan property for the header cell
|
||||
*/
|
||||
function makeTableHeader($type,$header,$colspan=2) {
|
||||
$this->initializeHeader($header);
|
||||
$this->renderTableHeader($type,$header,$colspan);
|
||||
}
|
||||
|
||||
//!draws the main table header
|
||||
/*!
|
||||
@param string $type name of the style of the header cell
|
||||
@param string $text the text of the header cell
|
||||
@param integer $colspan colspan property for the header cell
|
||||
*/
|
||||
function renderTableHeader($type,$text,$colspan=0){
|
||||
echo '<table cellspacing=2 cellpadding=3 class="dBug_'.$type.'">
|
||||
<tr>
|
||||
<td '.(($this->bCollapsed) ? 'style="font-style:italic" ' : '').'class="dBug_'.$type.'Header" '.($colspan?'colspan='.$colspan:'').' onClick="dBug_toggleTable(this)">'.$text.'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
//!renders table of 2 cells [type][value]
|
||||
/*!
|
||||
@param string $headerStyle name of the style of the header cell
|
||||
@param string $header the text of the header cell
|
||||
@param string $value the text of the value cell
|
||||
@param string $valueStyle name of the style of the value cell
|
||||
@param integer $colspan colspan property for the header cell
|
||||
*/
|
||||
function renderPrimitiveType($headerStyle,$header,$value,$valueStyle=null,$colspan=0){
|
||||
if(!$valueStyle)$valueStyle=$headerStyle;
|
||||
$this->initializeHeader($header);
|
||||
echo '<table cellspacing=2 cellpadding=3 class="dBug_'.$headerStyle.'">
|
||||
<tr>
|
||||
<td '.(($this->bCollapsed) ? 'style="font-style:italic" ' : '').'class="dBug_'.$headerStyle.'Header" '.($colspan?'colspan='.$colspan:'').' onClick="dBug_toggleTable(this)">'
|
||||
.$header.
|
||||
'</td>
|
||||
<td valign="top" onClick="dBug_toggleRow(this)" class="dBug_'.$valueStyle.'">'.$value.'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
//!creates the table row header
|
||||
/*!
|
||||
@param string $type name of the style of the key cell
|
||||
@param string $header the text of the key cell
|
||||
*/
|
||||
function makeTDHeader($type,$header) {
|
||||
$str_d = ($this->bCollapsed) ? " style=\"display:none\"" : "";
|
||||
echo "<tr".$str_d.">
|
||||
|
@ -103,12 +161,14 @@ class dBug {
|
|||
<td>";
|
||||
}
|
||||
|
||||
//close table row
|
||||
//!closes table row
|
||||
function closeTDRow() {
|
||||
return "</td></tr>\n";
|
||||
}
|
||||
//!@}
|
||||
|
||||
//error
|
||||
|
||||
//!prints error
|
||||
function error($type) {
|
||||
$error="Error: Variable cannot be a";
|
||||
// this just checks if the type starts with a vowel or "x" and displays either "a" or "an"
|
||||
|
@ -117,170 +177,186 @@ class dBug {
|
|||
return ($error." ".$type." type");
|
||||
}
|
||||
|
||||
//check variable type
|
||||
//!check variable type andd process the value in right way
|
||||
function checkType($var) {
|
||||
$type=gettype($var);
|
||||
switch($type) {
|
||||
case "resource":
|
||||
case 'resource':
|
||||
$this->varIsResource($var);
|
||||
break;
|
||||
case "object":
|
||||
case 'object':
|
||||
$this->varIsObject($var);
|
||||
break;
|
||||
case "array":
|
||||
case 'array':
|
||||
$this->varIsArray($var);
|
||||
break;
|
||||
case "integer":
|
||||
case "double":
|
||||
case 'integer':
|
||||
case 'double':
|
||||
$this->varIsNumeric($var,$type);
|
||||
break;
|
||||
case "NULL":
|
||||
case 'NULL':
|
||||
$this->varIsNULL();
|
||||
break;
|
||||
case "boolean":
|
||||
case 'boolean':
|
||||
$this->varIsBoolean($var);
|
||||
break;
|
||||
case "string":
|
||||
case 'string':
|
||||
$this->varIsString($var);
|
||||
break;
|
||||
default:
|
||||
$var=($var=="") ? "[empty string]" : $var;
|
||||
$var=($var=='') ? '[empty string]' : $var;
|
||||
echo "<table cellspacing=0><tr>\n<td>".$var."</td>\n</tr>\n</table>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//if variable is a NULL type
|
||||
/*!
|
||||
@name functions for rendering different types
|
||||
*/
|
||||
//!@{
|
||||
|
||||
//!renders NULL as red-pink rectangle
|
||||
function varIsNULL() {
|
||||
$this->makeTableHeader("false","NULL");
|
||||
//echo "NULL";
|
||||
echo "</table>";
|
||||
$this->makeTableHeader('false','NULL');
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//if variable is a numeric type
|
||||
//!renders numeric types : integers and doubles
|
||||
function varIsNumeric($var,$type) {
|
||||
$this->makeTableHeader("numeric",$type."(".$var.")");
|
||||
echo "</table>";
|
||||
$this->renderPrimitiveType('numeric',$type,$var);
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//if variable is a string type
|
||||
/*!
|
||||
renders string either as primitive type (if it is short (less than $embeddedStringMaxLength chars)
|
||||
and contains of one line) or line-by-line (otherwise)
|
||||
*/
|
||||
function varIsString(&$var){
|
||||
if($var==""){
|
||||
$this->makeTableHeader("string","empty string");
|
||||
echo "</table>";
|
||||
if($var==''){
|
||||
$this->makeTableHeader('string','empty string');
|
||||
echo '</table>';
|
||||
return;
|
||||
}
|
||||
$this->makeTableHeader("string","string (".strlen($var).")");
|
||||
$length=strlen($var);
|
||||
$nv=htmlspecialchars($var);
|
||||
$lines=explode("\n",$nv);
|
||||
foreach($lines as $num=>$line){
|
||||
$this->makeTDHeader("string",$num);
|
||||
echo ($line==""?"[empty line]":$line);
|
||||
$this->closeTDRow("string");
|
||||
$linesCount=count($lines);
|
||||
if($linesCount==1 && $length<=self::$embeddedStringMaxLength){
|
||||
$this->renderPrimitiveType('string','string ['.$length.']',$var);
|
||||
}else{
|
||||
$this->makeTableHeader('string','string ('.$length.' chars @ '.$linesCount.' lines)');
|
||||
foreach($lines as $num=>$line){
|
||||
$this->makeTDHeader('string',$num);
|
||||
echo ($line==''?'[empty line]':$line);
|
||||
$this->closeTDRow('string');
|
||||
}
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
//if variable is a boolean type
|
||||
//!renders boolean variable
|
||||
function varIsBoolean(&$var) {
|
||||
$var?$this->makeTableHeader("numeric","boolean (TRUE)"):$this->makeTableHeader("false","boolean (FALSE)");
|
||||
echo $var;
|
||||
echo "</table>";
|
||||
$var?$this->renderPrimitiveType('boolean','boolean','TRUE','booleanTrue'):$this->renderPrimitiveType('boolean','boolean','FALSE','booleanFalse');
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//if variable is an array type
|
||||
|
||||
|
||||
function varIsArray(&$var) {
|
||||
$var_ser = serialize($var);
|
||||
array_push($this->arrHistory, $var_ser);
|
||||
|
||||
$this->makeTableHeader("array","array");
|
||||
$this->makeTableHeader('array','array');
|
||||
if(is_array($var)) {
|
||||
foreach($var as $key=>$value) {
|
||||
$this->makeTDHeader("array",$key);
|
||||
$this->makeTDHeader('array',$key);
|
||||
|
||||
//check for recursion
|
||||
if(is_array($value)) {
|
||||
$var_ser = serialize($value);
|
||||
if(in_array($var_ser, $this->arrHistory, TRUE))
|
||||
$value = "*RECURSION*";
|
||||
if(in_array($var_ser, $this->arrHistory, TRUE)){
|
||||
echo '*RECURSION*';
|
||||
echo $this->closeTDRow();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(in_array(gettype($value),$this->arrType))
|
||||
//if(in_array(gettype($value),$this->arrType))
|
||||
$this->checkType($value);
|
||||
else {
|
||||
/*else {
|
||||
$value=(trim($value)=="") ? "[empty string]" : $value;
|
||||
echo $value;
|
||||
}
|
||||
}*/
|
||||
echo $this->closeTDRow();
|
||||
}
|
||||
}
|
||||
else echo "<tr><td>".$this->error("array").$this->closeTDRow();
|
||||
else echo '<tr><td>'.$this->error('array').$this->closeTDRow();
|
||||
array_pop($this->arrHistory);
|
||||
echo "</table>";
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//if variable is an object type
|
||||
//! checks wheither variable is object of special type (using varIs*Object), and renders it if it is generic object
|
||||
function varIsObject(&$var) {
|
||||
if($this->varIsDBObject($var))return 1;
|
||||
|
||||
$var_ser = serialize($var);
|
||||
array_push($this->arrHistory, $var_ser);
|
||||
$this->makeTableHeader("object","object");
|
||||
$this->makeTableHeader('object','object');
|
||||
|
||||
if(is_object($var)) {
|
||||
$arrObjVars=get_object_vars($var);
|
||||
foreach($arrObjVars as $key=>$value) {
|
||||
|
||||
$value=(!is_object($value) && !is_array($value) && trim($value)=="") ? "[empty string]" : $value;
|
||||
$this->makeTDHeader("object",$key);
|
||||
//$value=(!is_object($value) && !is_array($value) && trim($value)=="") ? "[empty string]" : $value;
|
||||
$this->makeTDHeader('object',$key);
|
||||
|
||||
//check for recursion
|
||||
if(is_object($value)||is_array($value)) {
|
||||
$var_ser = serialize($value);
|
||||
if(in_array($var_ser, $this->arrHistory, TRUE)) {
|
||||
$value = (is_object($value)) ? "*RECURSION* -> $".get_class($value) : "*RECURSION*";
|
||||
|
||||
echo (is_object($value)) ? '*RECURSION* -> $'.get_class($value) : '*RECURSION*';
|
||||
echo $this->closeTDRow();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(in_array(gettype($value),$this->arrType))
|
||||
//if(in_array(gettype($value),$this->arrType))
|
||||
$this->checkType($value);
|
||||
else echo $value;
|
||||
//else
|
||||
//echo $value;
|
||||
echo $this->closeTDRow();
|
||||
}
|
||||
$arrObjMethods=get_class_methods(get_class($var));
|
||||
foreach($arrObjMethods as $key=>$value) {
|
||||
$this->makeTDHeader("object",$value);
|
||||
echo "[function]".$this->closeTDRow();
|
||||
$this->makeTDHeader('object',$value);
|
||||
echo '[function]'.$this->closeTDRow();
|
||||
}
|
||||
}
|
||||
else echo "<tr><td>".$this->error("object").$this->closeTDRow();
|
||||
else echo '<tr><td>'.$this->error('object').$this->closeTDRow();
|
||||
array_pop($this->arrHistory);
|
||||
echo "</table>";
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//if variable is a resource type
|
||||
|
||||
//!shows info about different resources, uses customized rendering founctions when needed
|
||||
function varIsResource($var) {
|
||||
$this->makeTableHeader("resourceC","resource",1);
|
||||
$this->makeTableHeader('resourceC','resource',1);
|
||||
echo "<tr>\n<td>\n";
|
||||
$restype=get_resource_type($var);
|
||||
switch($restype) {
|
||||
case "fbsql result":
|
||||
case "mssql result":
|
||||
case "msql query":
|
||||
case "pgsql result":
|
||||
case "sybase-db result":
|
||||
case "sybase-ct result":
|
||||
case "mysql result":
|
||||
$db=current(explode(" ",$restype));
|
||||
case 'fbsql result':
|
||||
case 'mssql result':
|
||||
case 'msql query':
|
||||
case 'pgsql result':
|
||||
case 'sybase-db result':
|
||||
case 'sybase-ct result':
|
||||
case 'mysql result':
|
||||
$db=current(explode(' ',$restype));
|
||||
$this->varIsDBResource($var,$db);
|
||||
break;
|
||||
case "gd":
|
||||
case 'gd':
|
||||
$this->varIsGDResource($var);
|
||||
break;
|
||||
case "xml":
|
||||
case 'xml':
|
||||
$this->varIsXmlResource($var);
|
||||
break;
|
||||
case "curl":
|
||||
case 'curl':
|
||||
$this->varIsCurlEasyResource($var);
|
||||
break;
|
||||
/*case "curl_multi":
|
||||
|
@ -293,13 +369,74 @@ class dBug {
|
|||
echo $this->closeTDRow()."</table>\n";
|
||||
}
|
||||
|
||||
//!@}
|
||||
|
||||
/*!
|
||||
@name functions for rendering different resources
|
||||
*/
|
||||
//!@{
|
||||
|
||||
//!shows information about curl easy handles
|
||||
/*!simply iterates through handle info and displays everything which is not converted into false*/
|
||||
function varIsCurlEasyResource(&$var) {
|
||||
$this->makeTableHeader('resource','curl easy handle',2);
|
||||
$info=curl_getinfo($var);
|
||||
foreach($info as $name=>&$piece){
|
||||
if($piece){
|
||||
$this->makeTDHeader('resource',$name);
|
||||
//echo $piece.$this->closeTDRow();
|
||||
$this->checkType($piece);
|
||||
echo $this->closeTDRow();
|
||||
}
|
||||
}
|
||||
unset($info);
|
||||
echo '</table>';
|
||||
|
||||
}
|
||||
//!not implemented yet
|
||||
function varIsCurlMultiResource(&$var) {
|
||||
|
||||
}
|
||||
|
||||
//!if variable is an image/gd resource type
|
||||
function varIsGDResource($var) {
|
||||
$this->makeTableHeader('resource','gd',2);
|
||||
$this->makeTDHeader('resource','Width');
|
||||
$this->checkType(imagesx($var));
|
||||
echo $this->closeTDRow();
|
||||
$this->makeTDHeader('resource','Height');
|
||||
$this->checkType(imagesy($var));
|
||||
echo $this->closeTDRow();
|
||||
$this->makeTDHeader('resource','Colors');
|
||||
$this->checkType(imagecolorstotal($var));
|
||||
echo $this->closeTDRow();
|
||||
/*$this->makeTDHeader('resource','Image');
|
||||
touch('php://temp');
|
||||
imagepng($var,'php://temp');
|
||||
$img=file_get_contents('php://temp');
|
||||
echo $img;
|
||||
|
||||
echo '<img src="data:image/png;base64,'.base64_encode($img).'"/>'.$this->closeTDRow();*/
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//!@}
|
||||
|
||||
|
||||
/*!
|
||||
@name database results rendering functions
|
||||
*/
|
||||
//!@{
|
||||
|
||||
//!renders either PDO or SQLite3 statement objects
|
||||
/*!@returns 1 if the object is DB object, 0 otherwise*/
|
||||
function varIsDBObject($var) {
|
||||
$structure=array();
|
||||
$data=array();
|
||||
$retres=false;
|
||||
if($var instanceof SQLite3Result){
|
||||
//$var=clone $var;
|
||||
$dbtype="";
|
||||
$dbtype='';
|
||||
$count=$var->numColumns();
|
||||
for($i=0;$i<$count;$i++){
|
||||
$structure[$i]=array();
|
||||
|
@ -311,7 +448,7 @@ class dBug {
|
|||
$data[]=$res;
|
||||
}
|
||||
$var->reset();
|
||||
$dbtype="SQLite3";
|
||||
$dbtype='SQLite3';
|
||||
unset($var);
|
||||
$this->renderDBData($dbtype,$structure,$data);
|
||||
$retres=true;
|
||||
|
@ -324,13 +461,13 @@ class dBug {
|
|||
//$col=$var->getColumnMeta(0);
|
||||
$col=$var->getColumnMeta($i);
|
||||
$structure[$i]=array();
|
||||
$structure[$i][0]=$col["name"];
|
||||
$structure[$i][1]=(isset($col["driver:decl_type"])?(isset($col["len"])?"({$col["len"]})":"")."\n":"")."({$col["native_type"]})";
|
||||
$structure[$i][0]=$col['name'];
|
||||
$structure[$i][1]=(isset($col['driver:decl_type'])?(isset($col["len"])?"({$col["len"]})":'')."\n":'')."({$col["native_type"]})";
|
||||
}
|
||||
unset($col);
|
||||
$data=$var->fetchAll();
|
||||
$var->closeCursor();
|
||||
$dbtype="PDOStatement";
|
||||
$dbtype='PDOStatement';
|
||||
unset($var);
|
||||
$this->renderDBData($dbtype,$structure,$data);
|
||||
$retres=true;
|
||||
|
@ -340,44 +477,51 @@ class dBug {
|
|||
unset($structure);
|
||||
return $retres;
|
||||
}
|
||||
|
||||
//!renders database data
|
||||
/*!
|
||||
@param string $objectType type of the db, it is only the name of header now
|
||||
@param array $structure 'header' of the table - columns names and types
|
||||
@param array $data rows of sql request result
|
||||
*/
|
||||
function renderDBData(&$objectType,&$structure,&$data){
|
||||
$this->makeTableHeader("database",$objectType,count($structure)+1);
|
||||
echo "<tr><td class=\"dBug_databaseKey\"> </td>";
|
||||
$this->makeTableHeader('database',$objectType,count($structure)+1);
|
||||
echo '<tr><td class="dBug_databaseKey"> </td>';
|
||||
foreach($structure as $field) {
|
||||
echo '<td class="dBug_databaseKey"'.(isset($field[1])?' title="'.$field[1].'"':"").'>'.$field[0]."</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo '</tr>';
|
||||
if(empty($data)){
|
||||
echo "<tr><td class=\"dBug_resourceKey\" colspan=\"".(count($structure)+1)."\">[empty result]</td></tr>";
|
||||
echo '<tr><td class="dBug_resourceKey" colspan="'.(count($structure)+1).'">[empty result]</td></tr>';
|
||||
}else
|
||||
$i=0;
|
||||
foreach($data as $row) {
|
||||
echo "<tr>\n";
|
||||
echo "<td class=\"dBug_resourceKey\">".(++$i)."</td>";
|
||||
echo '<td class="dBug_resourceKey">'.(++$i).'</td>';
|
||||
for($k=0;$k<count($row);$k++) {
|
||||
$fieldrow=($row[$k]==="") ? "[empty string]" : $row[$k];
|
||||
echo "<td>".$fieldrow."</td>\n";
|
||||
$fieldrow=($row[$k]==='') ? '[empty string]' : $row[$k];
|
||||
echo '<td>'.$fieldrow."</td>\n";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>";
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//if variable is a database resource type
|
||||
function varIsDBResource($var,$db="mysql") {
|
||||
if($db == "pgsql")
|
||||
$db = "pg";
|
||||
if($db == "sybase-db" || $db == "sybase-ct")
|
||||
$db = "sybase";
|
||||
$arrFields = array("name","type","flags");
|
||||
$numrows=call_user_func($db."_num_rows",$var);
|
||||
$numfields=call_user_func($db."_num_fields",$var);
|
||||
$this->makeTableHeader("database",$db." result",$numfields+1);
|
||||
echo "<tr><td class=\"dBug_databaseKey\"> </td>";
|
||||
//!renders database resource (fetch result) into table or ... smth else
|
||||
function varIsDBResource($var,$db='mysql') {
|
||||
if($db == 'pgsql')
|
||||
$db = 'pg';
|
||||
if($db == 'sybase-db' || $db == 'sybase-ct')
|
||||
$db = 'sybase';
|
||||
$arrFields = array('name','type','flags');
|
||||
$numrows=call_user_func($db.'_num_rows',$var);
|
||||
$numfields=call_user_func($db.'_num_fields',$var);
|
||||
$this->makeTableHeader('database',$db.' result',$numfields+1);
|
||||
echo '<tr><td class="dBug_databaseKey"> </td>';
|
||||
for($i=0;$i<$numfields;$i++) {
|
||||
$field_header = "";
|
||||
$field_header = '';
|
||||
for($j=0; $j<count($arrFields); $j++) {
|
||||
$db_func = $db."_field_".$arrFields[$j];
|
||||
$db_func = $db.'_field_'.$arrFields[$j];
|
||||
if(function_exists($db_func)) {
|
||||
$fheader = call_user_func($db_func, $var, $i). " ";
|
||||
if($j==0)
|
||||
|
@ -386,74 +530,62 @@ class dBug {
|
|||
$field_header .= $fheader;
|
||||
}
|
||||
}
|
||||
$field[$i]=call_user_func($db."_fetch_field",$var,$i);
|
||||
echo "<td class=\"dBug_databaseKey\" title=\"".$field_header."\">".$field_name."</td>";
|
||||
$field[$i]=call_user_func($db.'_fetch_field',$var,$i);
|
||||
echo '<td class="dBug_databaseKey" title="'.$field_header.'">'.$field_name.'</td>';
|
||||
}
|
||||
echo "</tr>";
|
||||
echo '</tr>';
|
||||
for($i=0;$i<$numrows;$i++) {
|
||||
$row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC"));
|
||||
echo "<tr>\n";
|
||||
echo "<td class=\"dBug_databaseKey\">".($i+1)."</td>";
|
||||
echo '<td class="dBug_databaseKey">'.($i+1).'</td>';
|
||||
for($k=0;$k<$numfields;$k++) {
|
||||
$tempField=$field[$k]->name;
|
||||
$fieldrow=$row[($field[$k]->name)];
|
||||
$fieldrow=($fieldrow=="") ? "[empty string]" : $fieldrow;
|
||||
echo "<td>".$fieldrow."</td>\n";
|
||||
$fieldrow=($fieldrow=='') ? '[empty string]' : $fieldrow;
|
||||
echo '<td>'.$fieldrow."</td>\n";
|
||||
}
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>";
|
||||
echo '</table>';
|
||||
if($numrows>0)
|
||||
call_user_func($db."_data_seek",$var,0);
|
||||
call_user_func($db.'_data_seek',$var,0);
|
||||
}
|
||||
//!@}
|
||||
|
||||
//if variable is an image/gd resource type
|
||||
function varIsGDResource($var) {
|
||||
$this->makeTableHeader("resource","gd",2);
|
||||
$this->makeTDHeader("resource","Width");
|
||||
echo imagesx($var).$this->closeTDRow();
|
||||
$this->makeTDHeader("resource","Height");
|
||||
echo imagesy($var).$this->closeTDRow();
|
||||
$this->makeTDHeader("resource","Colors");
|
||||
echo imagecolorstotal($var).$this->closeTDRow();
|
||||
/*$this->makeTDHeader("resource","Image");
|
||||
touch('php://temp');
|
||||
imagepng($var,'php://temp');
|
||||
$img=file_get_contents('php://temp');
|
||||
echo $img;
|
||||
|
||||
echo '<img src="data:image/png;base64,'.base64_encode($img).'"/>'.$this->closeTDRow();*/
|
||||
echo "</table>";
|
||||
}
|
||||
/*!
|
||||
@name xml rendering functions
|
||||
*/
|
||||
//!@{
|
||||
|
||||
//if variable is an xml type
|
||||
//!if variable is an xml type
|
||||
//!remember, that you must force type to xml to use this
|
||||
function varIsXml($var) {
|
||||
$this->varIsXmlResource($var);
|
||||
}
|
||||
|
||||
//if variable is an xml resource type
|
||||
//!if variable is an xml resource type
|
||||
function varIsXmlResource($var) {
|
||||
$xml_parser=xml_parser_create();
|
||||
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
|
||||
xml_set_element_handler($xml_parser,array(&$this,"xmlStartElement"),array(&$this,"xmlEndElement"));
|
||||
xml_set_character_data_handler($xml_parser,array(&$this,"xmlCharacterData"));
|
||||
xml_set_default_handler($xml_parser,array(&$this,"xmlDefaultHandler"));
|
||||
xml_set_element_handler($xml_parser,array(&$this,'xmlStartElement'),array(&$this,'xmlEndElement'));
|
||||
xml_set_character_data_handler($xml_parser,array(&$this,'xmlCharacterData'));
|
||||
xml_set_default_handler($xml_parser,array(&$this,'xmlDefaultHandler'));
|
||||
|
||||
$this->makeTableHeader("xml","xml document",2);
|
||||
$this->makeTDHeader("xml","xmlRoot");
|
||||
$this->makeTableHeader('xml','xml document',2);
|
||||
$this->makeTDHeader('xml','xmlRoot');
|
||||
|
||||
//attempt to open xml file
|
||||
$bFile=(!($fp=@fopen($var,"r"))) ? false : true;
|
||||
$bFile=(!($fp=@fopen($var,'r'))) ? false : true;
|
||||
|
||||
//read xml file
|
||||
if($bFile) {
|
||||
while($data=str_replace("\n","",fread($fp,4096)))
|
||||
while($data=str_replace("\n",'',fread($fp,4096)))
|
||||
$this->xmlParse($xml_parser,$data,feof($fp));
|
||||
}
|
||||
//if xml is not a file, attempt to read it as a string
|
||||
else {
|
||||
if(!is_string($var)) {
|
||||
echo $this->error("xml").$this->closeTDRow()."</table>\n";
|
||||
echo $this->error('xml').$this->closeTDRow()."</table>\n";
|
||||
return;
|
||||
}
|
||||
$data=$var;
|
||||
|
@ -464,24 +596,7 @@ class dBug {
|
|||
|
||||
}
|
||||
|
||||
function varIsCurlEasyResource(&$var) {
|
||||
$this->makeTableHeader("resource","curl easy handle",2);
|
||||
$info=curl_getinfo($var);
|
||||
foreach($info as $name=>&$piece){
|
||||
if($piece){
|
||||
$this->makeTDHeader("resource",$name);
|
||||
echo $piece.$this->closeTDRow();
|
||||
}
|
||||
}
|
||||
unset($info);
|
||||
echo "</table>";
|
||||
|
||||
}
|
||||
function varIsCurlMultiResource(&$var) {
|
||||
|
||||
}
|
||||
|
||||
//parse xml
|
||||
//!parses xml
|
||||
function xmlParse($xml_parser,$data,$bFinal) {
|
||||
if (!xml_parse($xml_parser,$data,$bFinal)) {
|
||||
die(sprintf("XML error: %s at line %d\n",
|
||||
|
@ -490,7 +605,7 @@ class dBug {
|
|||
}
|
||||
}
|
||||
|
||||
//xml: inititiated when a start tag is encountered
|
||||
//!xml: inititiated when a start tag is encountered
|
||||
function xmlStartElement($parser,$name,$attribs) {
|
||||
$this->xmlAttrib[$this->xmlCount]=$attribs;
|
||||
$this->xmlName[$this->xmlCount]=$name;
|
||||
|
@ -506,7 +621,7 @@ class dBug {
|
|||
$this->xmlCount++;
|
||||
}
|
||||
|
||||
//xml: initiated when an end tag is encountered
|
||||
//!xml: initiated when an end tag is encountered
|
||||
function xmlEndElement($parser,$name) {
|
||||
for($i=0;$i<$this->xmlCount;$i++) {
|
||||
eval($this->xmlSData[$i]);
|
||||
|
@ -516,15 +631,15 @@ class dBug {
|
|||
$this->makeTDHeader("xml","xmlComment");
|
||||
echo (!empty($this->xmlDData[$i])) ? $this->xmlDData[$i] : " ";
|
||||
echo $this->closeTDRow();
|
||||
$this->makeTDHeader("xml","xmlChildren");
|
||||
$this->makeTDHeader('xml',"xmlChildren");
|
||||
unset($this->xmlCData[$i],$this->xmlDData[$i]);
|
||||
}
|
||||
echo $this->closeTDRow();
|
||||
echo "</table>";
|
||||
echo '</table>';
|
||||
$this->xmlCount=0;
|
||||
}
|
||||
|
||||
//xml: initiated when text between tags is encountered
|
||||
//!xml: initiated when text between tags is encountered
|
||||
function xmlCharacterData($parser,$data) {
|
||||
$count=$this->xmlCount-1;
|
||||
if(!empty($this->xmlCData[$count]))
|
||||
|
@ -533,7 +648,9 @@ class dBug {
|
|||
$this->xmlCData[$count]=$data;
|
||||
}
|
||||
|
||||
//xml: initiated when a comment or other miscellaneous texts is encountered
|
||||
//!@}
|
||||
|
||||
//!xml: initiated when a comment or other miscellaneous texts is encountered
|
||||
function xmlDefaultHandler($parser,$data) {
|
||||
//strip '<!--' and '-->' off comments
|
||||
$data=str_replace(array("<!--","-->"),"",htmlspecialchars($data));
|
||||
|
@ -543,8 +660,9 @@ class dBug {
|
|||
else
|
||||
$this->xmlDData[$count]=$data;
|
||||
}
|
||||
|
||||
function initJSandCSS() {
|
||||
|
||||
//! adds needed JS and CSS sources to page
|
||||
static function initJSandCSS() {
|
||||
echo <<<SCRIPTS
|
||||
<script language="JavaScript">
|
||||
/* code modified from ColdFusion's cfdump code */
|
||||
|
@ -639,26 +757,37 @@ class dBug {
|
|||
table.dBug_xml td { background-color:#FFFFFF; }
|
||||
table.dBug_xml td.dBug_xmlHeader { background-color:#AAAAAA; }
|
||||
table.dBug_xml td.dBug_xmlKey { background-color:#DDDDDD; }
|
||||
/* FALSE */
|
||||
|
||||
/* FALSE and boolean false*/
|
||||
table.dBug_false { background-color:#CB0101; }
|
||||
table.dBug_false td { background-color:#FFFFFF; }
|
||||
table.dBug_false td.dBug_falseHeader { background-color:#F2054C; }
|
||||
table.dBug_boolean td.dBug_booleanFalse,table.dBug_false td.dBug_falseHeader { background-color:#F2054C; }
|
||||
table.dBug_false td.dBug_falseKey { background-color:#DDDDDD; }
|
||||
|
||||
/* numeric */
|
||||
table.dBug_numeric { background-color:#F9C007; }
|
||||
table.dBug_numeric td { background-color:#FFFFFF; }
|
||||
table.dBug_numeric td.dBug_numericHeader { background-color:#F2D904; }
|
||||
/*table.dBug_numeric td.dBug_numericKey { background-color:#DDDDDD; }*/
|
||||
//table.dBug_numeric td.dBug_numericKey { background-color:#DDDDDD; }
|
||||
|
||||
/* database */
|
||||
table.dBug_database { background-color:#8FB6E6 }
|
||||
table.dBug_database td { background-color:#07DDF9; }
|
||||
table.dBug_database td.dBug_databaseHeader { background-color:#07F7FB; }
|
||||
table.dBug_database td.dBug_databaseKey { background-color:#AEF4F5; }
|
||||
|
||||
/* string */
|
||||
table.dBug_string { background-color:#556832 }
|
||||
table.dBug_string td { background-color:#B3C520;}
|
||||
table.dBug_string td.dBug_stringHeader { background-color:#808000; }
|
||||
table.dBug_string td.dBug_stringKey { background-color:#96A428; }
|
||||
|
||||
/*boolean*/
|
||||
table.dBug_boolean { background-color:#43769F }
|
||||
table.dBug_boolean td.dBug_booleanHeader { background-color:#5EA5DE; }
|
||||
table.dBug_boolean td.dBug_booleanTrue { background-color:#04F258; }
|
||||
table.dBug_boolean td.dBug_booleanTrue,table.dBug_boolean td.dBug_booleanFalse { width:46px; text-align: center;border-radius: 45%;}
|
||||
|
||||
</style>
|
||||
SCRIPTS;
|
||||
}
|
||||
|
|
15
tests.php
15
tests.php
|
@ -1,19 +1,30 @@
|
|||
<?
|
||||
include_once(__DIR__.'/dBug.php');
|
||||
$a="The quick brown fox jumps over the lazy dog\nThe five boxing wizards jump quickly.\r\nСъешь же ещё этих мягких французских булок, да выпей чаю\n";
|
||||
new dBug($a);
|
||||
$a='vodka';
|
||||
new dBug($a);
|
||||
$a=3;
|
||||
new dBug($a);
|
||||
$a=3.5;
|
||||
new dBug($a);
|
||||
$a=null;
|
||||
new dBug($a);
|
||||
$a=true;
|
||||
new dBug($a);
|
||||
$a=false;
|
||||
new dBug($a);
|
||||
$variable = array(
|
||||
"first"=>"1",
|
||||
"second",
|
||||
"third"=>array(
|
||||
"inner third 1",
|
||||
"inner third 2"=>"yeah"),
|
||||
"fourth");
|
||||
"inner third 2"=>25),
|
||||
"fourth"=>49.36,
|
||||
'fifth'=>true,
|
||||
6=>false,
|
||||
NULL,
|
||||
);
|
||||
new dBug($variable);
|
||||
class Vegetable {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue