added namespaces
fixed string rendering (added support for unicode strings) And other minor fixes PS droped compatibility with php 4
This commit is contained in:
parent
1662b22231
commit
62df2b9155
5 changed files with 296 additions and 258 deletions
1
.php_cs
1
.php_cs
|
@ -13,4 +13,3 @@ return Symfony\CS\Config\Config::create()
|
|||
->fixers(array('-indentation','-braces','-psr0','-controls_spaces'))
|
||||
->finder($finder)
|
||||
;
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
dBug
|
||||
====
|
||||
|
||||
my mod of dBug
|
||||
A debug output library which is used to visualize different datatypes.
|
||||
Initially was developed by ospinto.
|
||||
|
||||
For more info visit [http://kolanich.github.com/dBug/]
|
||||
|
||||

|
||||
|
||||
## Very very brief list of features
|
||||
|
||||
PHP version of ColdFusion’s cfdump.
|
||||
Extended PHP version of ColdFusion’s cfdump.
|
||||
|
||||
Outputs colored and structured tabular variable information.
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name" : "KOLANICH/dBug",
|
||||
"type" : "library",
|
||||
"description" : "A debug output library which is used to visualize different datatypes.",
|
||||
"keywords" : ["debug", "output", "table", "visualization"],
|
||||
"keywords" : ["debug", "output", "table", "visualization","cfdump","ColdFusion"],
|
||||
"homepage" : "https://github.com/KOLANICH/dBug",
|
||||
"license" : "GPL-2.0",
|
||||
"authors" : [{
|
||||
|
@ -17,7 +17,7 @@
|
|||
}
|
||||
],
|
||||
"require" : {
|
||||
"php" : ">=4.1.0"
|
||||
"php" : ">=5.2"
|
||||
},
|
||||
"suggest" : {
|
||||
"ext-Reflection" : "to show protected and private info (now is only implemented for Exceptions)"
|
||||
|
|
285
dBug.php
285
dBug.php
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?PHP
|
||||
/*********************************************************************************************************************\
|
||||
*
|
||||
* USAGE
|
||||
|
@ -20,26 +20,26 @@
|
|||
* new dBug ( $strXml, "xml" );
|
||||
*
|
||||
\*********************************************************************************************************************/
|
||||
|
||||
/*!
|
||||
@author ospinto
|
||||
@author KOLANICH
|
||||
*/
|
||||
class dBug {
|
||||
|
||||
var $xmlDepth=array();
|
||||
var $xmlCData;
|
||||
var $xmlSData;
|
||||
var $xmlDData;
|
||||
var $xmlCount=0;
|
||||
var $xmlAttrib;
|
||||
var $xmlName;
|
||||
namespace dBug;
|
||||
class dBug
|
||||
{
|
||||
public $xmlDepth=array();
|
||||
public $xmlCData;
|
||||
public $xmlSData;
|
||||
public $xmlDData;
|
||||
public $xmlCount=0;
|
||||
public $xmlAttrib;
|
||||
public $xmlName;
|
||||
//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();
|
||||
public $bInitialized = false;
|
||||
public $bCollapsed = false;
|
||||
public $arrHistory = array();
|
||||
static $embeddedStringMaxLength=50;
|
||||
|
||||
/*!
|
||||
|
@ -47,9 +47,10 @@ class dBug {
|
|||
@param string $forceType type to marshall $var to show
|
||||
@param boolean $bCollapsed should output be collapsed
|
||||
*/
|
||||
function dBug($var,$forceType="",$bCollapsed=false) {
|
||||
public function __construct($var,$forceType="",$bCollapsed=false)
|
||||
{
|
||||
//include js and css scripts
|
||||
if(!defined('BDBUGINIT')) {
|
||||
if (!defined('BDBUGINIT')) {
|
||||
define('BDBUGINIT', TRUE);
|
||||
self::initJSandCSS();
|
||||
}
|
||||
|
@ -62,14 +63,15 @@ class dBug {
|
|||
}
|
||||
|
||||
//get variable name
|
||||
function getVariableName() {
|
||||
public function getVariableName()
|
||||
{
|
||||
$arrBacktrace = debug_backtrace();
|
||||
|
||||
//possible 'included' functions
|
||||
$arrInclude = array("include","include_once","require","require_once");
|
||||
|
||||
//check for any included/required files. if found, get array of the last included file (they contain the right line numbers)
|
||||
for($i=count($arrBacktrace)-1; $i>=0; $i--) {
|
||||
for ($i=count($arrBacktrace)-1; $i>=0; $i--) {
|
||||
$arrCurrent = $arrBacktrace[$i];
|
||||
if(array_key_exists("function", $arrCurrent) &&
|
||||
(in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug"))))
|
||||
|
@ -80,7 +82,7 @@ class dBug {
|
|||
break;
|
||||
}
|
||||
|
||||
if(isset($arrFile)) {
|
||||
if (isset($arrFile)) {
|
||||
$arrLines = file($arrFile["file"]);
|
||||
$code = $arrLines[($arrFile["line"]-1)];
|
||||
|
||||
|
@ -89,11 +91,13 @@ class dBug {
|
|||
|
||||
return isset($arrMatches[1])?$arrMatches[1]:'[multiline]';
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
function initializeHeader(&$header){
|
||||
if(!$this->bInitialized) {
|
||||
public function initializeHeader(&$header)
|
||||
{
|
||||
if (!$this->bInitialized) {
|
||||
$header = $this->getVariableName() . " (" . $header . ")";
|
||||
$this->bInitialized = true;
|
||||
}
|
||||
|
@ -111,7 +115,8 @@ class dBug {
|
|||
@param string $header the text of the header cell
|
||||
@param integer $colspan colspan property for the header cell
|
||||
*/
|
||||
function makeTableHeader($type,$header,$colspan=2) {
|
||||
public function makeTableHeader($type,$header,$colspan=2)
|
||||
{
|
||||
$this->initializeHeader($header);
|
||||
$this->renderTableHeader($type,$header,$colspan);
|
||||
}
|
||||
|
@ -122,7 +127,8 @@ class dBug {
|
|||
@param string $text the text of the header cell
|
||||
@param integer $colspan colspan property for the header cell
|
||||
*/
|
||||
function renderTableHeader($type,$text,$colspan=0){
|
||||
public 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>
|
||||
|
@ -137,7 +143,8 @@ class dBug {
|
|||
@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){
|
||||
public 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.'">
|
||||
|
@ -153,32 +160,36 @@ class dBug {
|
|||
@param string $type name of the style of the key cell
|
||||
@param string $header the text of the key cell
|
||||
*/
|
||||
function makeTDHeader($type,$header) {
|
||||
public function makeTDHeader($type,$header)
|
||||
{
|
||||
echo '<tr'.($this->bCollapsed ? ' style="display:none"' : '').'>
|
||||
<td valign="top" onClick="dBug_toggleRow(this)" class="dBug_'.$type.'Key">'.$header.'</td>
|
||||
<td>';
|
||||
}
|
||||
|
||||
//!closes table row
|
||||
function closeTDRow() {
|
||||
public function closeTDRow()
|
||||
{
|
||||
return "</td></tr>\n";
|
||||
}
|
||||
//!@}
|
||||
|
||||
|
||||
//!prints error
|
||||
function error($type) {
|
||||
public 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"
|
||||
if(in_array(substr($type,0,1),array("a","e","i","o","u","x")))
|
||||
$error.="n";
|
||||
return ($error." ".$type." type");
|
||||
if(in_array(substr($type,0,1),array('a','e','i','o','u','x')))
|
||||
$error.='n';
|
||||
|
||||
return ($error.' '.$type.' type');
|
||||
}
|
||||
|
||||
//!check variable type andd process the value in right way
|
||||
function checkType($var) {
|
||||
public function checkType($var)
|
||||
{
|
||||
$type=gettype($var);
|
||||
switch($type) {
|
||||
switch ($type) {
|
||||
case 'resource':
|
||||
$this->varIsResource($var);
|
||||
break;
|
||||
|
@ -214,13 +225,15 @@ class dBug {
|
|||
//!@{
|
||||
|
||||
//!renders NULL as red-pink rectangle
|
||||
function varIsNULL() {
|
||||
public function varIsNULL()
|
||||
{
|
||||
$this->makeTableHeader('false','NULL');
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
//!renders numeric types : integers and doubles
|
||||
function varIsNumeric($var,$type) {
|
||||
public function varIsNumeric($var,$type)
|
||||
{
|
||||
$this->renderPrimitiveType('numeric',$type,$var);
|
||||
echo '</table>';
|
||||
}
|
||||
|
@ -229,21 +242,23 @@ class dBug {
|
|||
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==''){
|
||||
public function varIsString(&$var)
|
||||
{
|
||||
if ($var=='') {
|
||||
$this->makeTableHeader('string','empty string');
|
||||
echo '</table>';
|
||||
|
||||
return;
|
||||
}
|
||||
$length=strlen($var);
|
||||
$nv=htmlspecialchars($var,ENT_QUOTES | ENT_SUBSTITUTE,'');
|
||||
$lines=preg_split('/\R/', $nv);
|
||||
$lines=preg_split('/\R/u', $nv);
|
||||
$linesCount=count($lines);
|
||||
if($linesCount==1 && $length<=self::$embeddedStringMaxLength){
|
||||
if ($linesCount==1 && $length<=self::$embeddedStringMaxLength) {
|
||||
$this->renderPrimitiveType('string','string ['.$length.']',$var);
|
||||
}else{
|
||||
} else {
|
||||
$this->makeTableHeader('string','string ('.$length.' chars @ '.$linesCount.' lines)');
|
||||
foreach($lines as $num=>$line){
|
||||
foreach ($lines as $num=>$line) {
|
||||
$this->makeTDHeader('string',$num);
|
||||
echo ($line==''?'[empty line]':$line);
|
||||
$this->closeTDRow('string');
|
||||
|
@ -253,25 +268,26 @@ class dBug {
|
|||
}
|
||||
|
||||
//!renders boolean variable
|
||||
function varIsBoolean(&$var) {
|
||||
public function varIsBoolean(&$var)
|
||||
{
|
||||
$var?$this->renderPrimitiveType('boolean','boolean','TRUE','booleanTrue'):$this->renderPrimitiveType('boolean','boolean','FALSE','booleanFalse');
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
|
||||
function varIsArray(&$var) {
|
||||
public function varIsArray(&$var)
|
||||
{
|
||||
$var_ser = serialize($var);
|
||||
array_push($this->arrHistory, $var_ser);
|
||||
|
||||
$this->makeTableHeader('array','array');
|
||||
if(is_array($var)) {
|
||||
foreach($var as $key=>$value) {
|
||||
if (is_array($var)) {
|
||||
foreach ($var as $key=>$value) {
|
||||
$this->makeTDHeader('array',$key);
|
||||
|
||||
//check for recursion
|
||||
if(is_array($value)) {
|
||||
if (is_array($value)) {
|
||||
$var_ser = serialize($value);
|
||||
if(in_array($var_ser, $this->arrHistory, TRUE)){
|
||||
if (in_array($var_ser, $this->arrHistory, TRUE)) {
|
||||
echo '*RECURSION*';
|
||||
echo $this->closeTDRow();
|
||||
continue;
|
||||
|
@ -286,40 +302,38 @@ class dBug {
|
|||
}*/
|
||||
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>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! checks wheither variable is object of special type (using varIs*Object), and renders it if it is generic object
|
||||
function varIsObject(&$var) {
|
||||
public function varIsObject(&$var)
|
||||
{
|
||||
if($this->varIsSpecialObject($var))return 1;
|
||||
$var_ser = serialize($var);
|
||||
array_push($this->arrHistory, $var_ser);
|
||||
|
||||
if(is_object($var)) {
|
||||
if (is_object($var)) {
|
||||
$this->makeTableHeader('object','object ( '.get_class($var).' )');
|
||||
if(method_exists($var,'__toString')){
|
||||
if (method_exists($var,'__toString')) {
|
||||
$str=$var->__toString();
|
||||
if($str!==null){
|
||||
if ($str!==null) {
|
||||
$this->makeTDHeader('string','[string representation]');
|
||||
$this->varIsString($str);
|
||||
echo $this->closeTDRow();
|
||||
}
|
||||
}
|
||||
$arrObjVars=get_object_vars($var);
|
||||
foreach($arrObjVars as $key=>$value) {
|
||||
foreach ($arrObjVars as $key=>$value) {
|
||||
|
||||
//$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)) {
|
||||
if (is_object($value)||is_array($value)) {
|
||||
$var_ser = serialize($value);
|
||||
if(in_array($var_ser, $this->arrHistory, TRUE)) {
|
||||
if (in_array($var_ser, $this->arrHistory, TRUE)) {
|
||||
echo (is_object($value)) ? '*RECURSION* -> $'.get_class($value) : '*RECURSION*';
|
||||
echo $this->closeTDRow();
|
||||
continue;
|
||||
|
@ -332,19 +346,18 @@ class dBug {
|
|||
echo $this->closeTDRow();
|
||||
}
|
||||
$arrObjMethods=get_class_methods(get_class($var));
|
||||
foreach($arrObjMethods as $key=>$value) {
|
||||
foreach ($arrObjMethods as $key=>$value) {
|
||||
$this->makeTDHeader('object',$value);
|
||||
echo '[function]'.$this->closeTDRow();
|
||||
}
|
||||
if($var instanceof \Iterator){
|
||||
foreach($var as $key=>$value) {
|
||||
if ($var instanceof \Iterator) {
|
||||
foreach ($var as $key=>$value) {
|
||||
$this->makeTDHeader('array',$key);
|
||||
$this->checkType($value);
|
||||
echo $this->closeTDRow();
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$this->makeTableHeader('object','object');
|
||||
echo '<tr><td>'.$this->error('object').$this->closeTDRow();
|
||||
}
|
||||
|
@ -352,22 +365,25 @@ class dBug {
|
|||
echo '</table>';
|
||||
}
|
||||
|
||||
function varIsSpecialObject(&$var){
|
||||
public function varIsSpecialObject(&$var)
|
||||
{
|
||||
if($this->varIsDBObject($var))return 1;
|
||||
if($var instanceof Exception){
|
||||
if ($var instanceof \Exception) {
|
||||
$this->varIsException($var);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//!shows info about different resources, uses customized rendering founctions when needed
|
||||
function varIsResource($var) {
|
||||
public function varIsResource($var)
|
||||
{
|
||||
$this->makeTableHeader('resourceC','resource',1);
|
||||
echo "<tr>\n<td>\n";
|
||||
$restype=get_resource_type($var);
|
||||
switch($restype) {
|
||||
switch ($restype) {
|
||||
case 'fbsql result':
|
||||
case 'mssql result':
|
||||
case 'msql query':
|
||||
|
@ -406,11 +422,12 @@ class dBug {
|
|||
|
||||
//!shows information about curl easy handles
|
||||
/*!simply iterates through handle info and displays everything which is not converted into false*/
|
||||
function varIsCurlEasyResource(&$var) {
|
||||
public function varIsCurlEasyResource(&$var)
|
||||
{
|
||||
$this->makeTableHeader('resource','curl easy handle',2);
|
||||
$info=curl_getinfo($var);
|
||||
foreach($info as $name=>&$piece){
|
||||
if($piece){
|
||||
foreach ($info as $name=>&$piece) {
|
||||
if ($piece) {
|
||||
$this->makeTDHeader('resource',$name);
|
||||
//echo $piece.$this->closeTDRow();
|
||||
$this->checkType($piece);
|
||||
|
@ -422,12 +439,13 @@ class dBug {
|
|||
|
||||
}
|
||||
//!not implemented yet
|
||||
function varIsCurlMultiResource(&$var) {
|
||||
|
||||
public function varIsCurlMultiResource(&$var)
|
||||
{
|
||||
}
|
||||
|
||||
//!if variable is an image/gd resource type
|
||||
function varIsGDResource(&$var) {
|
||||
public function varIsGDResource(&$var)
|
||||
{
|
||||
$this->makeTableHeader('resource','gd',2);
|
||||
$this->makeTDHeader('resource','Width');
|
||||
$this->checkType(imagesx($var));
|
||||
|
@ -441,11 +459,9 @@ class dBug {
|
|||
|
||||
$this->makeTDHeader('resource','Image');
|
||||
|
||||
|
||||
|
||||
ob_start();
|
||||
imagepng($var);
|
||||
$img = ob_get_clean();
|
||||
imagepng($var);
|
||||
$img = ob_get_clean();
|
||||
|
||||
echo '<img src="data:image/png;base64,'.base64_encode($img).'"/>'.$this->closeTDRow();
|
||||
echo '</table>';
|
||||
|
@ -453,7 +469,6 @@ class dBug {
|
|||
|
||||
//!@}
|
||||
|
||||
|
||||
/*!
|
||||
@name database results rendering functions
|
||||
*/
|
||||
|
@ -461,21 +476,22 @@ class dBug {
|
|||
|
||||
//!renders either PDO or SQLite3 statement objects
|
||||
/*!@returns 1 if the object is DB object, 0 otherwise*/
|
||||
function varIsDBObject($var) {
|
||||
public function varIsDBObject($var)
|
||||
{
|
||||
$structure=array();
|
||||
$data=array();
|
||||
$retres=false;
|
||||
if($var instanceof SQLite3Result){
|
||||
if ($var instanceof \SQLite3Result) {
|
||||
//$var=clone $var;
|
||||
$dbtype='';
|
||||
$count=$var->numColumns();
|
||||
for($i=0;$i<$count;$i++){
|
||||
for ($i=0;$i<$count;$i++) {
|
||||
$structure[$i]=array();
|
||||
$structure[$i][0]=$var->columnName($i);
|
||||
$structure[$i][1]=$var->columnType($i);
|
||||
}
|
||||
$var->reset();
|
||||
while($res=$var->fetchArray(SQLITE3_NUM)){
|
||||
while ($res=$var->fetchArray(SQLITE3_NUM)) {
|
||||
$data[]=$res;
|
||||
}
|
||||
$var->reset();
|
||||
|
@ -484,11 +500,11 @@ class dBug {
|
|||
$this->renderDBData($dbtype,$structure,$data);
|
||||
$retres=true;
|
||||
}
|
||||
if($var instanceof PDOStatement){
|
||||
if ($var instanceof \PDOStatement) {
|
||||
//$var=clone $var;
|
||||
$count=$var->columnCount();
|
||||
$col=null;
|
||||
for($i=0;$i<$count;$i++){
|
||||
for ($i=0;$i<$count;$i++) {
|
||||
//$col=$var->getColumnMeta(0);
|
||||
$col=$var->getColumnMeta($i);
|
||||
$structure[$i]=array();
|
||||
|
@ -506,6 +522,7 @@ class dBug {
|
|||
unset($dbtype);
|
||||
unset($data);
|
||||
unset($structure);
|
||||
|
||||
return $retres;
|
||||
}
|
||||
|
||||
|
@ -515,21 +532,22 @@ class dBug {
|
|||
@param array $structure 'header' of the table - columns names and types
|
||||
@param array $data rows of sql request result
|
||||
*/
|
||||
function renderDBData(&$objectType,&$structure,&$data){
|
||||
public function renderDBData(&$objectType,&$structure,&$data)
|
||||
{
|
||||
$this->makeTableHeader('database',$objectType,count($structure)+1);
|
||||
echo '<tr><td class="dBug_databaseKey"> </td>';
|
||||
foreach($structure as $field) {
|
||||
foreach ($structure as $field) {
|
||||
echo '<td class="dBug_databaseKey"'.(isset($field[1])?' title="'.$field[1].'"':"").'>'.$field[0]."</td>";
|
||||
}
|
||||
echo '</tr>';
|
||||
if(empty($data)){
|
||||
if (empty($data)) {
|
||||
echo '<tr><td class="dBug_resourceKey" colspan="'.(count($structure)+1).'">[empty result]</td></tr>';
|
||||
}else
|
||||
$i=0;
|
||||
foreach($data as $row) {
|
||||
foreach ($data as $row) {
|
||||
echo "<tr>\n";
|
||||
echo '<td class="dBug_resourceKey">'.(++$i).'</td>';
|
||||
for($k=0;$k<count($row);$k++) {
|
||||
for ($k=0;$k<count($row);$k++) {
|
||||
$fieldrow=($row[$k]==='') ? '[empty string]' : $row[$k];
|
||||
echo '<td>'.$fieldrow."</td>\n";
|
||||
}
|
||||
|
@ -539,7 +557,8 @@ class dBug {
|
|||
}
|
||||
|
||||
//!renders database resource (fetch result) into table or ... smth else
|
||||
function varIsDBResource($var,$db='mysql') {
|
||||
public function varIsDBResource($var,$db='mysql')
|
||||
{
|
||||
if($db == 'pgsql')
|
||||
$db = 'pg';
|
||||
if($db == 'sybase-db' || $db == 'sybase-ct')
|
||||
|
@ -549,11 +568,11 @@ class dBug {
|
|||
$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++) {
|
||||
for ($i=0;$i<$numfields;$i++) {
|
||||
$field_header = '';
|
||||
for($j=0; $j<count($arrFields); $j++) {
|
||||
for ($j=0; $j<count($arrFields); $j++) {
|
||||
$db_func = $db.'_field_'.$arrFields[$j];
|
||||
if(function_exists($db_func)) {
|
||||
if (function_exists($db_func)) {
|
||||
$fheader = call_user_func($db_func, $var, $i). " ";
|
||||
if($j==0)
|
||||
$field_name = $fheader;
|
||||
|
@ -565,11 +584,11 @@ class dBug {
|
|||
echo '<td class="dBug_databaseKey" title="'.$field_header.'">'.$field_name.'</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
for($i=0;$i<$numrows;$i++) {
|
||||
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>';
|
||||
for($k=0;$k<$numfields;$k++) {
|
||||
for ($k=0;$k<$numfields;$k++) {
|
||||
$tempField=$field[$k]->name;
|
||||
$fieldrow=$row[($field[$k]->name)];
|
||||
$fieldrow=($fieldrow=='') ? '[empty string]' : $fieldrow;
|
||||
|
@ -583,7 +602,6 @@ class dBug {
|
|||
}
|
||||
//!@}
|
||||
|
||||
|
||||
/*!
|
||||
@name other special kinds of objects rendering functionality
|
||||
*/
|
||||
|
@ -602,20 +620,21 @@ class dBug {
|
|||
Renders exceptions : at first basic fields, then custom fields.
|
||||
Custom private and protected fields are rendered if reflection api is available
|
||||
*/
|
||||
function varIsException(&$var) {
|
||||
public function varIsException(&$var)
|
||||
{
|
||||
$code=$var->getCode();
|
||||
$this->makeTableHeader('Exception',get_class($var).' :: '.$code);
|
||||
foreach(static::$exceptionMainProps as &$pname) {
|
||||
foreach (static::$exceptionMainProps as &$pname) {
|
||||
$this->makeTDHeader('Exception',$pname);
|
||||
$this->checkType($var->{'get'.ucfirst($pname)}());
|
||||
echo $this->closeTDRow();
|
||||
}
|
||||
unset($pname);
|
||||
echo '<tr><td></td></tr>';
|
||||
if(extension_loaded('Reflection')){
|
||||
$refl=new ReflectionObject($var);
|
||||
if (extension_loaded('Reflection')) {
|
||||
$refl=new \ReflectionObject($var);
|
||||
$props=$refl->getProperties(ReflectionProperty::IS_PROTECTED|ReflectionProperty::IS_PRIVATE);
|
||||
foreach($props as &$prop) {
|
||||
foreach ($props as &$prop) {
|
||||
$pname=$prop->getName();
|
||||
if(in_array($pname,static::$exceptionMainProps)||in_array($pname,static::$exceptionExcludedProps))continue;
|
||||
$this->makeTDHeader('Exception',$pname);
|
||||
|
@ -626,7 +645,7 @@ class dBug {
|
|||
}
|
||||
}
|
||||
|
||||
foreach($var as $key=>&$value) {
|
||||
foreach ($var as $key=>&$value) {
|
||||
if($key=='xdebug_message')continue;
|
||||
$this->makeTDHeader('Exception',$key);
|
||||
$this->checkType($value);
|
||||
|
@ -638,8 +657,6 @@ class dBug {
|
|||
|
||||
//!@}
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
@name xml rendering functions
|
||||
*/
|
||||
|
@ -647,12 +664,14 @@ class dBug {
|
|||
|
||||
//!if variable is an xml type
|
||||
//!remember, that you must force type to xml to use this
|
||||
function varIsXml($var) {
|
||||
public function varIsXml($var)
|
||||
{
|
||||
$this->varIsXmlResource($var);
|
||||
}
|
||||
|
||||
//!if variable is an xml resource type
|
||||
function varIsXmlResource($var) {
|
||||
public 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'));
|
||||
|
@ -666,14 +685,15 @@ class dBug {
|
|||
$bFile=(!($fp=@fopen($var,'r'))) ? false : true;
|
||||
|
||||
//read xml file
|
||||
if($bFile) {
|
||||
if ($bFile) {
|
||||
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)) {
|
||||
if (!is_string($var)) {
|
||||
echo $this->error('xml').$this->closeTDRow()."</table>\n";
|
||||
|
||||
return;
|
||||
}
|
||||
$data=$var;
|
||||
|
@ -685,16 +705,18 @@ class dBug {
|
|||
}
|
||||
|
||||
//!parses xml
|
||||
function xmlParse($xml_parser,$data,$bFinal) {
|
||||
public function xmlParse($xml_parser,$data,$bFinal)
|
||||
{
|
||||
if (!xml_parse($xml_parser,$data,$bFinal)) {
|
||||
die(sprintf("XML error: %s at line %d\n",
|
||||
throw new \Exception(sprintf("dBug XML error: %s at line %d\n",
|
||||
xml_error_string(xml_get_error_code($xml_parser)),
|
||||
xml_get_current_line_number($xml_parser)));
|
||||
}
|
||||
}
|
||||
|
||||
//!xml: inititiated when a start tag is encountered
|
||||
function xmlStartElement($parser,$name,$attribs) {
|
||||
public function xmlStartElement($parser,$name,$attribs)
|
||||
{
|
||||
$this->xmlAttrib[$this->xmlCount]=$attribs;
|
||||
$this->xmlName[$this->xmlCount]=$name;
|
||||
$this->xmlSData[$this->xmlCount]='$this->makeTableHeader("xml","xml element",2);';
|
||||
|
@ -710,8 +732,9 @@ class dBug {
|
|||
}
|
||||
|
||||
//!xml: initiated when an end tag is encountered
|
||||
function xmlEndElement($parser,$name) {
|
||||
for($i=0;$i<$this->xmlCount;$i++) {
|
||||
public function xmlEndElement($parser,$name)
|
||||
{
|
||||
for ($i=0;$i<$this->xmlCount;$i++) {
|
||||
eval($this->xmlSData[$i]);
|
||||
$this->makeTDHeader("xml","xmlText");
|
||||
echo (!empty($this->xmlCData[$i])) ? $this->xmlCData[$i] : " ";
|
||||
|
@ -728,7 +751,8 @@ class dBug {
|
|||
}
|
||||
|
||||
//!xml: initiated when text between tags is encountered
|
||||
function xmlCharacterData($parser,$data) {
|
||||
public function xmlCharacterData($parser,$data)
|
||||
{
|
||||
$count=$this->xmlCount-1;
|
||||
if(!empty($this->xmlCData[$count]))
|
||||
$this->xmlCData[$count].=$data;
|
||||
|
@ -739,7 +763,8 @@ class dBug {
|
|||
//!@}
|
||||
|
||||
//!xml: initiated when a comment or other miscellaneous texts is encountered
|
||||
function xmlDefaultHandler($parser,$data) {
|
||||
public function xmlDefaultHandler($parser,$data)
|
||||
{
|
||||
//strip '<!--' and '-->' off comments
|
||||
$data=str_replace(array("<!--","-->"),"",htmlspecialchars($data));
|
||||
$count=$this->xmlCount-1;
|
||||
|
@ -750,45 +775,51 @@ class dBug {
|
|||
}
|
||||
|
||||
//! adds needed JS and CSS sources to page
|
||||
static function initJSandCSS() {
|
||||
public static function initJSandCSS()
|
||||
{
|
||||
echo <<<SCRIPTS
|
||||
<script language="JavaScript">
|
||||
/* code modified from ColdFusion's cfdump code */
|
||||
function dBug_toggleRow(source) {
|
||||
function dBug_toggleRow(source)
|
||||
{
|
||||
var target = (document.all) ? source.parentElement.cells[1] : source.parentNode.lastChild;
|
||||
dBug_toggleTarget(target,dBug_toggleSource(source));
|
||||
}
|
||||
|
||||
function dBug_toggleSource(source) {
|
||||
function dBug_toggleSource(source)
|
||||
{
|
||||
if (source.style.fontStyle=='italic') {
|
||||
source.style.fontStyle='normal';
|
||||
source.title='click to collapse';
|
||||
|
||||
return 'open';
|
||||
} else {
|
||||
source.style.fontStyle='italic';
|
||||
source.title='click to expand';
|
||||
|
||||
return 'closed';
|
||||
}
|
||||
}
|
||||
|
||||
function dBug_toggleTarget(target,switchToState) {
|
||||
function dBug_toggleTarget(target,switchToState)
|
||||
{
|
||||
target.style.display = (switchToState=='open') ? '' : 'none';
|
||||
}
|
||||
|
||||
function dBug_toggleTable(source) {
|
||||
function dBug_toggleTable(source)
|
||||
{
|
||||
var switchToState=dBug_toggleSource(source);
|
||||
if(document.all) {
|
||||
if (document.all) {
|
||||
var table=source.parentElement.parentElement;
|
||||
for(var i=1;i<table.rows.length;i++) {
|
||||
for (var i=1;i<table.rows.length;i++) {
|
||||
target=table.rows[i];
|
||||
dBug_toggleTarget(target,switchToState);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var table=source.parentNode.parentNode;
|
||||
for (var i=1;i<table.childNodes.length;i++) {
|
||||
target=table.childNodes[i];
|
||||
if(target.style) {
|
||||
if (target.style) {
|
||||
dBug_toggleTarget(target,switchToState);
|
||||
}
|
||||
}
|
||||
|
|
43
tests.php
43
tests.php
|
@ -1,5 +1,10 @@
|
|||
<?
|
||||
<?PHP
|
||||
namespace dBug\tests;
|
||||
ini_set('display_errors',1);
|
||||
error_reporting(E_ALL ^E_NOTICE);
|
||||
header('Content-Type: text/html;charset=utf-8;');
|
||||
include_once(__DIR__.'/dBug.php');
|
||||
use dBug\dBug;
|
||||
$a="The quick brown fox jumps over the lazy dog\nThe five boxing wizards jump quickly.\r\nСъешь же ещё этих мягких французских булок, да выпей чаю\n";
|
||||
new dBug($a);
|
||||
$a='vodka';
|
||||
|
@ -28,26 +33,28 @@
|
|||
new dBug($variable);
|
||||
class Vegetable {
|
||||
|
||||
var $edible;
|
||||
var $color;
|
||||
function Vegetable($edible, $color="green") {
|
||||
$this->edible = $edible;
|
||||
$this->color = $color;
|
||||
}
|
||||
var $edible;
|
||||
var $color;
|
||||
function Vegetable($edible, $color="green") {
|
||||
$this->edible = $edible;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
function is_edible() {
|
||||
return $this->edible;
|
||||
}
|
||||
function is_edible() {
|
||||
return $this->edible;
|
||||
}
|
||||
|
||||
function what_color() {
|
||||
return $this->color;
|
||||
}
|
||||
function what_color() {
|
||||
return $this->color;
|
||||
}
|
||||
}
|
||||
new dBug(new Vegetable("spinach"));
|
||||
$a=curl_init("http://github.com/");
|
||||
$a=curl_init("https://github.com/");
|
||||
new dBug($a);
|
||||
//curl_exec($a);
|
||||
//new dBug($a);
|
||||
|
||||
class myExc extends Exception{
|
||||
class myExc extends \Exception{
|
||||
private $priv="PREVED";
|
||||
protected $ololo="trololol";
|
||||
public $num=0;
|
||||
|
@ -58,12 +65,12 @@
|
|||
};
|
||||
try{
|
||||
throw new myExc("MedVed");
|
||||
}catch(Exception $e){
|
||||
}catch(\Exception $e){
|
||||
new dBug($e);
|
||||
}
|
||||
try{
|
||||
throw new Exception("hahahahaha");
|
||||
}catch(Exception $e){
|
||||
throw new \Exception("hahahahaha");
|
||||
}catch(\Exception $e){
|
||||
new dBug($e);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue