From 90b37524762f7f5df299bc16e0de4aee64abeb75 Mon Sep 17 00:00:00 2001 From: Sunra Date: Mon, 3 Dec 2012 15:22:51 +0200 Subject: [PATCH 01/28] Add PSR-0 support --- composer.json | 22 ++ lib/Ospinto/Dbug.php | 532 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 554 insertions(+) create mode 100644 composer.json create mode 100644 lib/Ospinto/Dbug.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5e0b4fd --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "sunra/dBug", + "version": "0.1.0", + "type": "library", + "description": "Most beautiful variable dump library for PHP (ColdFusion like style)", + "keywords": ["php","dump","debug"], + "homepage": "http://github.com/sunra/dBug.git", + "license": "MIT", + "authors": [ + { + "name": "sunra", + "email": "sunra@yandex.ru", + "homepage": "http://github.com/sunra" + } + ], + "require": { + "php": ">=5.3.2" + }, + "autoload": { + "psr-0": {"Ospinto\\Dbug": "lib/"} + } +} \ No newline at end of file diff --git a/lib/Ospinto/Dbug.php b/lib/Ospinto/Dbug.php new file mode 100644 index 0000000..1865470 --- /dev/null +++ b/lib/Ospinto/Dbug.php @@ -0,0 +1,532 @@ +initJSandCSS(); + } + $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); + else + $this->checkType($var); + } + + //get variable name + 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--) { + $arrCurrent = $arrBacktrace[$i]; + if(array_key_exists("function", $arrCurrent) && + (in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug")))) + continue; + + $arrFile = $arrCurrent; + + break; + } + + if(isset($arrFile)) { + $arrLines = file($arrFile["file"]); + $code = $arrLines[($arrFile["line"]-1)]; + + //find call to dBug class + preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); + + return $arrMatches[1]; + } + return ""; + } + + //create the main table header + function makeTableHeader($type,$header,$colspan=2) { + if(!$this->bInitialized) { + $header = $this->getVariableName() . " (" . $header . ")"; + $this->bInitialized = true; + } + $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; + + echo " + + + "; + } + + //create the table row header + function makeTDHeader($type,$header) { + $str_d = ($this->bCollapsed) ? " style=\"display:none\"" : ""; + echo " + + \n"; + } + + //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" + if(in_array(substr($type,0,1),array("a","e","i","o","u","x"))) + $error.="n"; + return ($error." ".$type." type"); + } + + //check variable type + function checkType($var) { + switch(gettype($var)) { + case "resource": + $this->varIsResource($var); + break; + case "object": + $this->varIsObject($var); + break; + case "array": + $this->varIsArray($var); + break; + case "NULL": + $this->varIsNULL(); + break; + case "boolean": + $this->varIsBoolean($var); + break; + default: + $var=($var=="") ? "[empty string]" : $var; + echo "
".$header."
".$header.""; + } + + //close table row + function closeTDRow() { + return "
\n\n\n
".$var."
\n"; + break; + } + } + + //if variable is a NULL type + function varIsNULL() { + echo "NULL"; + } + + //if variable is a boolean type + function varIsBoolean($var) { + $var=($var==1) ? "TRUE" : "FALSE"; + echo $var; + } + + //if variable is an array type + 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) { + $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(gettype($value),$this->arrType)) + $this->checkType($value); + else { + $value=(trim($value)=="") ? "[empty string]" : $value; + echo $value; + } + echo $this->closeTDRow(); + } + } + else echo "".$this->error("array").$this->closeTDRow(); + array_pop($this->arrHistory); + echo ""; + } + + //if variable is an object type + function varIsObject($var) { + $var_ser = serialize($var); + array_push($this->arrHistory, $var_ser); + $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); + + //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*"; + + } + } + if(in_array(gettype($value),$this->arrType)) + $this->checkType($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(); + } + } + else echo "".$this->error("object").$this->closeTDRow(); + array_pop($this->arrHistory); + echo ""; + } + + //if variable is a resource type + function varIsResource($var) { + $this->makeTableHeader("resourceC","resource",1); + echo "\n\n"; + switch(get_resource_type($var)) { + 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(" ",get_resource_type($var))); + $this->varIsDBResource($var,$db); + break; + case "gd": + $this->varIsGDResource($var); + break; + case "xml": + $this->varIsXmlResource($var); + break; + default: + echo get_resource_type($var).$this->closeTDRow(); + break; + } + echo $this->closeTDRow()."\n"; + } + + //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("resource",$db." result",$numfields+1); + echo " "; + for($i=0;$i<$numfields;$i++) { + $field_header = ""; + for($j=0; $j".$field_name.""; + } + echo ""; + for($i=0;$i<$numrows;$i++) { + $row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC")); + echo "\n"; + echo "".($i+1).""; + for($k=0;$k<$numfields;$k++) { + $tempField=$field[$k]->name; + $fieldrow=$row[($field[$k]->name)]; + $fieldrow=($fieldrow=="") ? "[empty string]" : $fieldrow; + echo "".$fieldrow."\n"; + } + echo "\n"; + } + echo ""; + if($numrows>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(); + echo ""; + } + + //if variable is an xml type + function varIsXml($var) { + $this->varIsXmlResource($var); + } + + //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")); + + $this->makeTableHeader("xml","xml document",2); + $this->makeTDHeader("xml","xmlRoot"); + + //attempt to open xml file + $bFile=(!($fp=@fopen($var,"r"))) ? false : true; + + //read xml file + 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)) { + echo $this->error("xml").$this->closeTDRow()."\n"; + return; + } + $data=$var; + $this->xmlParse($xml_parser,$data,1); + } + + echo $this->closeTDRow()."\n"; + + } + + //parse xml + function xmlParse($xml_parser,$data,$bFinal) { + if (!xml_parse($xml_parser,$data,$bFinal)) { + die(sprintf("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) { + $this->xmlAttrib[$this->xmlCount]=$attribs; + $this->xmlName[$this->xmlCount]=$name; + $this->xmlSData[$this->xmlCount]='$this->makeTableHeader("xml","xml element",2);'; + $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlName");'; + $this->xmlSData[$this->xmlCount].='echo "'.$this->xmlName[$this->xmlCount].'".$this->closeTDRow();'; + $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlAttributes");'; + if(count($attribs)>0) + $this->xmlSData[$this->xmlCount].='$this->varIsArray($this->xmlAttrib['.$this->xmlCount.']);'; + else + $this->xmlSData[$this->xmlCount].='echo " ";'; + $this->xmlSData[$this->xmlCount].='echo $this->closeTDRow();'; + $this->xmlCount++; + } + + //xml: initiated when an end tag is encountered + 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] : " "; + echo $this->closeTDRow(); + $this->makeTDHeader("xml","xmlComment"); + echo (!empty($this->xmlDData[$i])) ? $this->xmlDData[$i] : " "; + echo $this->closeTDRow(); + $this->makeTDHeader("xml","xmlChildren"); + unset($this->xmlCData[$i],$this->xmlDData[$i]); + } + echo $this->closeTDRow(); + echo ""; + $this->xmlCount=0; + } + + //xml: initiated when text between tags is encountered + function xmlCharacterData($parser,$data) { + $count=$this->xmlCount-1; + if(!empty($this->xmlCData[$count])) + $this->xmlCData[$count].=$data; + else + $this->xmlCData[$count]=$data; + } + + //xml: initiated when a comment or other miscellaneous texts is encountered + function xmlDefaultHandler($parser,$data) { + //strip '' off comments + $data=str_replace(array("<!--","-->"),"",htmlspecialchars($data)); + $count=$this->xmlCount-1; + if(!empty($this->xmlDData[$count])) + $this->xmlDData[$count].=$data; + else + $this->xmlDData[$count]=$data; + } + + function initJSandCSS() { + echo << + /* code modified from ColdFusion's cfdump code */ + 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) { + 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) { + target.style.display = (switchToState=='open') ? '' : 'none'; + } + + function dBug_toggleTable(source) { + var switchToState=dBug_toggleSource(source); + if(document.all) { + var table=source.parentElement.parentElement; + for(var i=1;i + + +SCRIPTS; + } + +} From 67e4e43b21fc1e7faf58a2a5a022ef26b91932ea Mon Sep 17 00:00:00 2001 From: Sunra Date: Mon, 3 Dec 2012 15:26:14 +0200 Subject: [PATCH 02/28] Changed directory structure Added composer support --- dBug.php | 531 ------------------------------------------------------- 1 file changed, 531 deletions(-) delete mode 100755 dBug.php diff --git a/dBug.php b/dBug.php deleted file mode 100755 index bc109b7..0000000 --- a/dBug.php +++ /dev/null @@ -1,531 +0,0 @@ -initJSandCSS(); - } - $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); - else - $this->checkType($var); - } - - //get variable name - 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--) { - $arrCurrent = $arrBacktrace[$i]; - if(array_key_exists("function", $arrCurrent) && - (in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug")))) - continue; - - $arrFile = $arrCurrent; - - break; - } - - if(isset($arrFile)) { - $arrLines = file($arrFile["file"]); - $code = $arrLines[($arrFile["line"]-1)]; - - //find call to dBug class - preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); - - return $arrMatches[1]; - } - return ""; - } - - //create the main table header - function makeTableHeader($type,$header,$colspan=2) { - if(!$this->bInitialized) { - $header = $this->getVariableName() . " (" . $header . ")"; - $this->bInitialized = true; - } - $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; - - echo " - - - "; - } - - //create the table row header - function makeTDHeader($type,$header) { - $str_d = ($this->bCollapsed) ? " style=\"display:none\"" : ""; - echo " - - \n"; - } - - //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" - if(in_array(substr($type,0,1),array("a","e","i","o","u","x"))) - $error.="n"; - return ($error." ".$type." type"); - } - - //check variable type - function checkType($var) { - switch(gettype($var)) { - case "resource": - $this->varIsResource($var); - break; - case "object": - $this->varIsObject($var); - break; - case "array": - $this->varIsArray($var); - break; - case "NULL": - $this->varIsNULL(); - break; - case "boolean": - $this->varIsBoolean($var); - break; - default: - $var=($var=="") ? "[empty string]" : $var; - echo "
".$header."
".$header.""; - } - - //close table row - function closeTDRow() { - return "
\n\n\n
".$var."
\n"; - break; - } - } - - //if variable is a NULL type - function varIsNULL() { - echo "NULL"; - } - - //if variable is a boolean type - function varIsBoolean($var) { - $var=($var==1) ? "TRUE" : "FALSE"; - echo $var; - } - - //if variable is an array type - 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) { - $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(gettype($value),$this->arrType)) - $this->checkType($value); - else { - $value=(trim($value)=="") ? "[empty string]" : $value; - echo $value; - } - echo $this->closeTDRow(); - } - } - else echo "".$this->error("array").$this->closeTDRow(); - array_pop($this->arrHistory); - echo ""; - } - - //if variable is an object type - function varIsObject($var) { - $var_ser = serialize($var); - array_push($this->arrHistory, $var_ser); - $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); - - //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*"; - - } - } - if(in_array(gettype($value),$this->arrType)) - $this->checkType($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(); - } - } - else echo "".$this->error("object").$this->closeTDRow(); - array_pop($this->arrHistory); - echo ""; - } - - //if variable is a resource type - function varIsResource($var) { - $this->makeTableHeader("resourceC","resource",1); - echo "\n\n"; - switch(get_resource_type($var)) { - 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(" ",get_resource_type($var))); - $this->varIsDBResource($var,$db); - break; - case "gd": - $this->varIsGDResource($var); - break; - case "xml": - $this->varIsXmlResource($var); - break; - default: - echo get_resource_type($var).$this->closeTDRow(); - break; - } - echo $this->closeTDRow()."\n"; - } - - //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("resource",$db." result",$numfields+1); - echo " "; - for($i=0;$i<$numfields;$i++) { - $field_header = ""; - for($j=0; $j".$field_name.""; - } - echo ""; - for($i=0;$i<$numrows;$i++) { - $row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC")); - echo "\n"; - echo "".($i+1).""; - for($k=0;$k<$numfields;$k++) { - $tempField=$field[$k]->name; - $fieldrow=$row[($field[$k]->name)]; - $fieldrow=($fieldrow=="") ? "[empty string]" : $fieldrow; - echo "".$fieldrow."\n"; - } - echo "\n"; - } - echo ""; - if($numrows>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(); - echo ""; - } - - //if variable is an xml type - function varIsXml($var) { - $this->varIsXmlResource($var); - } - - //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")); - - $this->makeTableHeader("xml","xml document",2); - $this->makeTDHeader("xml","xmlRoot"); - - //attempt to open xml file - $bFile=(!($fp=@fopen($var,"r"))) ? false : true; - - //read xml file - 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)) { - echo $this->error("xml").$this->closeTDRow()."\n"; - return; - } - $data=$var; - $this->xmlParse($xml_parser,$data,1); - } - - echo $this->closeTDRow()."\n"; - - } - - //parse xml - function xmlParse($xml_parser,$data,$bFinal) { - if (!xml_parse($xml_parser,$data,$bFinal)) { - die(sprintf("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) { - $this->xmlAttrib[$this->xmlCount]=$attribs; - $this->xmlName[$this->xmlCount]=$name; - $this->xmlSData[$this->xmlCount]='$this->makeTableHeader("xml","xml element",2);'; - $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlName");'; - $this->xmlSData[$this->xmlCount].='echo "'.$this->xmlName[$this->xmlCount].'".$this->closeTDRow();'; - $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlAttributes");'; - if(count($attribs)>0) - $this->xmlSData[$this->xmlCount].='$this->varIsArray($this->xmlAttrib['.$this->xmlCount.']);'; - else - $this->xmlSData[$this->xmlCount].='echo " ";'; - $this->xmlSData[$this->xmlCount].='echo $this->closeTDRow();'; - $this->xmlCount++; - } - - //xml: initiated when an end tag is encountered - 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] : " "; - echo $this->closeTDRow(); - $this->makeTDHeader("xml","xmlComment"); - echo (!empty($this->xmlDData[$i])) ? $this->xmlDData[$i] : " "; - echo $this->closeTDRow(); - $this->makeTDHeader("xml","xmlChildren"); - unset($this->xmlCData[$i],$this->xmlDData[$i]); - } - echo $this->closeTDRow(); - echo ""; - $this->xmlCount=0; - } - - //xml: initiated when text between tags is encountered - function xmlCharacterData($parser,$data) { - $count=$this->xmlCount-1; - if(!empty($this->xmlCData[$count])) - $this->xmlCData[$count].=$data; - else - $this->xmlCData[$count]=$data; - } - - //xml: initiated when a comment or other miscellaneous texts is encountered - function xmlDefaultHandler($parser,$data) { - //strip '' off comments - $data=str_replace(array("<!--","-->"),"",htmlspecialchars($data)); - $count=$this->xmlCount-1; - if(!empty($this->xmlDData[$count])) - $this->xmlDData[$count].=$data; - else - $this->xmlDData[$count]=$data; - } - - function initJSandCSS() { - echo << - /* code modified from ColdFusion's cfdump code */ - 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) { - 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) { - target.style.display = (switchToState=='open') ? '' : 'none'; - } - - function dBug_toggleTable(source) { - var switchToState=dBug_toggleSource(source); - if(document.all) { - var table=source.parentElement.parentElement; - for(var i=1;i - - -SCRIPTS; - } - -} -?> \ No newline at end of file From dadf63decc83ab431e3f60bc25368fd803e6d5f2 Mon Sep 17 00:00:00 2001 From: Sunra Date: Mon, 3 Dec 2012 15:29:16 +0200 Subject: [PATCH 03/28] composer packet name corrected --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5e0b4fd..ed0ccd4 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "sunra/dBug", + "name": "sunra/dbug", "version": "0.1.0", "type": "library", "description": "Most beautiful variable dump library for PHP (ColdFusion like style)", From 5609d2ddff084b59524c476615f7314931e5414a Mon Sep 17 00:00:00 2001 From: Sunra Date: Mon, 3 Dec 2012 16:11:02 +0200 Subject: [PATCH 04/28] Class constructor and var name detection corrected --- lib/Ospinto/Dbug.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Ospinto/Dbug.php b/lib/Ospinto/Dbug.php index 1865470..b708097 100644 --- a/lib/Ospinto/Dbug.php +++ b/lib/Ospinto/Dbug.php @@ -61,9 +61,12 @@ class Dbug { var $bInitialized = false; var $bCollapsed = false; var $arrHistory = array(); + private $var_name = ''; //constructor - function dBug($var,$forceType="",$bCollapsed=false) { + function __construct($var,$forceType="",$bCollapsed=false, $var_name='') { + if ($var_name) $this->var_name = $var_name; + //include js and css scripts if(!defined('BDBUGINIT')) { define("BDBUGINIT", TRUE); @@ -79,6 +82,7 @@ function dBug($var,$forceType="",$bCollapsed=false) { //get variable name function getVariableName() { + if ($this->var_name) return $this->var_name; $arrBacktrace = debug_backtrace(); //possible 'included' functions @@ -101,7 +105,7 @@ function getVariableName() { $code = $arrLines[($arrFile["line"]-1)]; //find call to dBug class - preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); + preg_match('/\bnew /\Ospinto/\Dbug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); return $arrMatches[1]; } From aa19d990bb57aaf002d4e938fb3defe9d1b87949 Mon Sep 17 00:00:00 2001 From: Sunra Date: Mon, 3 Dec 2012 16:15:25 +0200 Subject: [PATCH 05/28] class modified --- lib/Ospinto/Dbug.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Ospinto/Dbug.php b/lib/Ospinto/Dbug.php index b708097..6c9bf1d 100644 --- a/lib/Ospinto/Dbug.php +++ b/lib/Ospinto/Dbug.php @@ -1,5 +1,5 @@ Date: Mon, 3 Dec 2012 16:36:46 +0200 Subject: [PATCH 06/28] Readme updated --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 839418c..cc41d9d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,26 @@ # dBug -## How to use - include_once("dBug.php"); - new dBug($myVariable); +Install via Composer. +Class will be autoloaded. + + +use +``` php + + new \Ospinto\Dbug($myVariable); + +``` + +Class arguments: + + __construct ($var,$forceType="",$bCollapsed=false, $var_name='') + + $var - variable to dump, + $bCollapsed - view collapsed + $var_name - name of variable - displayed in dump header + + More examples at http://dbug.ospinto.com/examples.php From a71fafedd94eea2f85106024502f324766b575bf Mon Sep 17 00:00:00 2001 From: Sunra Date: Mon, 3 Dec 2012 16:51:37 +0200 Subject: [PATCH 07/28] readmy updated --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc41d9d..f5ca204 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,22 @@ # dBug +- Updated for PSR-0 copmliance +- created composer package +## Usage + Install via Composer. Class will be autoloaded. -use +### usage ``` php new \Ospinto\Dbug($myVariable); ``` -Class arguments: +### Class arguments: __construct ($var,$forceType="",$bCollapsed=false, $var_name='') From 78f200b18e1644fcfe13c883c3756b3d02ef8622 Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 21:36:07 +0200 Subject: [PATCH 08/28] Updated to August 6th, 2012 version of Ospinto's Dbug --- lib/Ospinto/Dbug.php | 168 ++++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/lib/Ospinto/Dbug.php b/lib/Ospinto/Dbug.php index 6c9bf1d..272b957 100644 --- a/lib/Ospinto/Dbug.php +++ b/lib/Ospinto/Dbug.php @@ -4,16 +4,21 @@ /*********************************************************************************************************************\ * LAST UPDATE * ============ - * March 22, 2007 + * August 6th, 2012 * * * AUTHOR * ============= - * Kwaku Otchere + * Kwaku Otchere * ospinto@hotmail.com - * + * + * AFTERMARKET HACKER + * ================== + * Josh Sherman + * josh@crowdsavings.com + * * Thanks to Andrew Hewitt (rudebwoy@hotmail.com) for the idea and suggestion - * + * * All the credit goes to ColdFusion's brilliant cfdump tag * Hope the next version of PHP can implement this or have something similar * I love PHP, but var_dump BLOWS!!! @@ -34,22 +39,22 @@ * example: * new dBug ( $myVariable ); * - * - * if the optional "forceType" string is given, the variable supplied to the - * function is forced to have that forceType type. + * + * if the optional "forceType" string is given, the variable supplied to the + * function is forced to have that forceType type. * example: new dBug( $myVariable , "array" ); - * will force $myVariable to be treated and dumped as an array type, + * will force $myVariable to be treated and dumped as an array type, * even though it might originally have been a string type, etc. * * NOTE! * ============== * forceType is REQUIRED for dumping an xml string or xml file * new dBug ( $strXml, "xml" ); - * + * \*********************************************************************************************************************/ -class Dbug { - +class dBug { + var $xmlDepth=array(); var $xmlCData; var $xmlSData; @@ -61,12 +66,9 @@ class Dbug { var $bInitialized = false; var $bCollapsed = false; var $arrHistory = array(); - private $var_name = ''; - + //constructor - function __construct($var,$forceType="",$bCollapsed=false, $var_name='') { - if ($var_name) $this->var_name = $var_name; - + function dBug($var,$forceType="",$bCollapsed=false) { //include js and css scripts if(!defined('BDBUGINIT')) { define("BDBUGINIT", TRUE); @@ -82,50 +84,49 @@ function __construct($var,$forceType="",$bCollapsed=false, $var_name='') { //get variable name function getVariableName() { - if ($this->var_name) return $this->var_name; $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--) { $arrCurrent = $arrBacktrace[$i]; - if(array_key_exists("function", $arrCurrent) && + if(array_key_exists("function", $arrCurrent) && (in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug")))) continue; $arrFile = $arrCurrent; - + break; } - + if(isset($arrFile)) { $arrLines = file($arrFile["file"]); $code = $arrLines[($arrFile["line"]-1)]; - + //find call to dBug class - preg_match('/\bnew /\Ospinto/\Dbug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); - + preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); + return $arrMatches[1]; } return ""; } - + //create the main table header function makeTableHeader($type,$header,$colspan=2) { if(!$this->bInitialized) { $header = $this->getVariableName() . " (" . $header . ")"; $this->bInitialized = true; } - $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; - + $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; + echo ""; } - + //create the table row header function makeTDHeader($type,$header) { $str_d = ($this->bCollapsed) ? " style=\"display:none\"" : ""; @@ -133,12 +134,12 @@ function makeTDHeader($type,$header) { \n"; } - + //error function error($type) { $error="Error: Variable cannot be a"; @@ -172,35 +173,35 @@ function checkType($var) { break; } } - + //if variable is a NULL type function varIsNULL() { echo "NULL"; } - + //if variable is a boolean type function varIsBoolean($var) { $var=($var==1) ? "TRUE" : "FALSE"; echo $var; } - + //if variable is an array type 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) { $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(gettype($value),$this->arrType)) $this->checkType($value); else { @@ -214,20 +215,20 @@ function varIsArray($var) { array_pop($this->arrHistory); echo "
".$header."
".$header." "; } - + //close table row function closeTDRow() { return "
"; } - + //if variable is an object type function varIsObject($var) { $var_ser = serialize($var); array_push($this->arrHistory, $var_ser); $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); - + //check for recursion if(is_object($value)||is_array($value)) { $var_ser = serialize($value); @@ -286,7 +287,7 @@ function varIsDBResource($var,$db="mysql") { $db = "pg"; if($db == "sybase-db" || $db == "sybase-ct") $db = "sybase"; - $arrFields = array("name","type","flags"); + $arrFields = array("name","type","flags"); $numrows=call_user_func($db."_num_rows",$var); $numfields=call_user_func($db."_num_fields",$var); $this->makeTableHeader("resource",$db." result",$numfields+1); @@ -310,7 +311,7 @@ function varIsDBResource($var,$db="mysql") { for($i=0;$i<$numrows;$i++) { $row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC")); echo "\n"; - echo "".($i+1).""; + echo "".($i+1).""; for($k=0;$k<$numfields;$k++) { $tempField=$field[$k]->name; $fieldrow=$row[($field[$k]->name)]; @@ -323,7 +324,7 @@ function varIsDBResource($var,$db="mysql") { if($numrows>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); @@ -335,26 +336,26 @@ function varIsGDResource($var) { echo imagecolorstotal($var).$this->closeTDRow(); echo ""; } - + //if variable is an xml type function varIsXml($var) { $this->varIsXmlResource($var); } - + //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_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_default_handler($xml_parser,array(&$this,"xmlDefaultHandler")); + $this->makeTableHeader("xml","xml document",2); $this->makeTDHeader("xml","xmlRoot"); - + //attempt to open xml file $bFile=(!($fp=@fopen($var,"r"))) ? false : true; - + //read xml file if($bFile) { while($data=str_replace("\n","",fread($fp,4096))) @@ -369,20 +370,20 @@ function varIsXmlResource($var) { $data=$var; $this->xmlParse($xml_parser,$data,1); } - + echo $this->closeTDRow()."\n"; - + } - + //parse xml function xmlParse($xml_parser,$data,$bFinal) { - if (!xml_parse($xml_parser,$data,$bFinal)) { - die(sprintf("XML error: %s at line %d\n", - xml_error_string(xml_get_error_code($xml_parser)), - xml_get_current_line_number($xml_parser))); + if (!xml_parse($xml_parser,$data,$bFinal)) { + die(sprintf("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) { $this->xmlAttrib[$this->xmlCount]=$attribs; @@ -397,8 +398,8 @@ function xmlStartElement($parser,$name,$attribs) { $this->xmlSData[$this->xmlCount].='echo " ";'; $this->xmlSData[$this->xmlCount].='echo $this->closeTDRow();'; $this->xmlCount++; - } - + } + //xml: initiated when an end tag is encountered function xmlEndElement($parser,$name) { for($i=0;$i<$this->xmlCount;$i++) { @@ -415,8 +416,8 @@ function xmlEndElement($parser,$name) { echo $this->closeTDRow(); echo ""; $this->xmlCount=0; - } - + } + //xml: initiated when text between tags is encountered function xmlCharacterData($parser,$data) { $count=$this->xmlCount-1; @@ -424,8 +425,8 @@ function xmlCharacterData($parser,$data) { $this->xmlCData[$count].=$data; else $this->xmlCData[$count]=$data; - } - + } + //xml: initiated when a comment or other miscellaneous texts is encountered function xmlDefaultHandler($parser,$data) { //strip '' off comments @@ -445,7 +446,7 @@ 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) { if (source.style.fontStyle=='italic') { source.style.fontStyle='normal'; @@ -457,11 +458,11 @@ function dBug_toggleSource(source) { return 'closed'; } } - + function dBug_toggleTarget(target,switchToState) { target.style.display = (switchToState=='open') ? '' : 'none'; } - + function dBug_toggleTable(source) { var switchToState=dBug_toggleSource(source); if(document.all) { @@ -482,48 +483,54 @@ function dBug_toggleTable(source) { } } - + +SCRIPTS; + } + +} + From a027f16dc852849c77fd29463e6d7a6183b1eeef Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 22:16:02 +0200 Subject: [PATCH 12/28] psr4 --- composer.json | 2 +- dBug.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9fd854b..d153e0a 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "php": ">=5.3.2" }, "autoload": { - "psr-4": {"Ospinto\\dBug": "dBug.php"} + "psr-4": {"Ospinto\\dBug": "/"} } } \ No newline at end of file diff --git a/dBug.php b/dBug.php index 85c1377..272b957 100644 --- a/dBug.php +++ b/dBug.php @@ -1,5 +1,4 @@ Date: Sat, 12 Dec 2015 22:21:20 +0200 Subject: [PATCH 13/28] psr4 2 --- lib/Ospinto/Dbug.php | 545 ------------------------------------------- 1 file changed, 545 deletions(-) delete mode 100644 lib/Ospinto/Dbug.php diff --git a/lib/Ospinto/Dbug.php b/lib/Ospinto/Dbug.php deleted file mode 100644 index 85c1377..0000000 --- a/lib/Ospinto/Dbug.php +++ /dev/null @@ -1,545 +0,0 @@ -initJSandCSS(); - } - $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); - else - $this->checkType($var); - } - - //get variable name - 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--) { - $arrCurrent = $arrBacktrace[$i]; - if(array_key_exists("function", $arrCurrent) && - (in_array($arrCurrent["function"], $arrInclude) || (0 != strcasecmp($arrCurrent["function"], "dbug")))) - continue; - - $arrFile = $arrCurrent; - - break; - } - - if(isset($arrFile)) { - $arrLines = file($arrFile["file"]); - $code = $arrLines[($arrFile["line"]-1)]; - - //find call to dBug class - preg_match('/\bnew dBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); - - return $arrMatches[1]; - } - return ""; - } - - //create the main table header - function makeTableHeader($type,$header,$colspan=2) { - if(!$this->bInitialized) { - $header = $this->getVariableName() . " (" . $header . ")"; - $this->bInitialized = true; - } - $str_i = ($this->bCollapsed) ? "style=\"font-style:italic\" " : ""; - - echo " - - - "; - } - - //create the table row header - function makeTDHeader($type,$header) { - $str_d = ($this->bCollapsed) ? " style=\"display:none\"" : ""; - echo " - - \n"; - } - - //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" - if(in_array(substr($type,0,1),array("a","e","i","o","u","x"))) - $error.="n"; - return ($error." ".$type." type"); - } - - //check variable type - function checkType($var) { - switch(gettype($var)) { - case "resource": - $this->varIsResource($var); - break; - case "object": - $this->varIsObject($var); - break; - case "array": - $this->varIsArray($var); - break; - case "NULL": - $this->varIsNULL(); - break; - case "boolean": - $this->varIsBoolean($var); - break; - default: - $var=($var=="") ? "[empty string]" : $var; - echo "
".$header."
".$header.""; - } - - //close table row - function closeTDRow() { - return "
\n\n\n
".$var."
\n"; - break; - } - } - - //if variable is a NULL type - function varIsNULL() { - echo "NULL"; - } - - //if variable is a boolean type - function varIsBoolean($var) { - $var=($var==1) ? "TRUE" : "FALSE"; - echo $var; - } - - //if variable is an array type - 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) { - $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(gettype($value),$this->arrType)) - $this->checkType($value); - else { - $value=(trim($value)=="") ? "[empty string]" : $value; - echo $value; - } - echo $this->closeTDRow(); - } - } - else echo "".$this->error("array").$this->closeTDRow(); - array_pop($this->arrHistory); - echo ""; - } - - //if variable is an object type - function varIsObject($var) { - $var_ser = serialize($var); - array_push($this->arrHistory, $var_ser); - $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); - - //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*"; - - } - } - if(in_array(gettype($value),$this->arrType)) - $this->checkType($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(); - } - } - else echo "".$this->error("object").$this->closeTDRow(); - array_pop($this->arrHistory); - echo ""; - } - - //if variable is a resource type - function varIsResource($var) { - $this->makeTableHeader("resourceC","resource",1); - echo "\n\n"; - switch(get_resource_type($var)) { - 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(" ",get_resource_type($var))); - $this->varIsDBResource($var,$db); - break; - case "gd": - $this->varIsGDResource($var); - break; - case "xml": - $this->varIsXmlResource($var); - break; - default: - echo get_resource_type($var).$this->closeTDRow(); - break; - } - echo $this->closeTDRow()."\n"; - } - - //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("resource",$db." result",$numfields+1); - echo " "; - for($i=0;$i<$numfields;$i++) { - $field_header = ""; - for($j=0; $j".$field_name.""; - } - echo ""; - for($i=0;$i<$numrows;$i++) { - $row=call_user_func($db."_fetch_array",$var,constant(strtoupper($db)."_ASSOC")); - echo "\n"; - echo "".($i+1).""; - for($k=0;$k<$numfields;$k++) { - $tempField=$field[$k]->name; - $fieldrow=$row[($field[$k]->name)]; - $fieldrow=($fieldrow=="") ? "[empty string]" : $fieldrow; - echo "".$fieldrow."\n"; - } - echo "\n"; - } - echo ""; - if($numrows>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(); - echo ""; - } - - //if variable is an xml type - function varIsXml($var) { - $this->varIsXmlResource($var); - } - - //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")); - - $this->makeTableHeader("xml","xml document",2); - $this->makeTDHeader("xml","xmlRoot"); - - //attempt to open xml file - $bFile=(!($fp=@fopen($var,"r"))) ? false : true; - - //read xml file - 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)) { - echo $this->error("xml").$this->closeTDRow()."\n"; - return; - } - $data=$var; - $this->xmlParse($xml_parser,$data,1); - } - - echo $this->closeTDRow()."\n"; - - } - - //parse xml - function xmlParse($xml_parser,$data,$bFinal) { - if (!xml_parse($xml_parser,$data,$bFinal)) { - die(sprintf("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) { - $this->xmlAttrib[$this->xmlCount]=$attribs; - $this->xmlName[$this->xmlCount]=$name; - $this->xmlSData[$this->xmlCount]='$this->makeTableHeader("xml","xml element",2);'; - $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlName");'; - $this->xmlSData[$this->xmlCount].='echo "'.$this->xmlName[$this->xmlCount].'".$this->closeTDRow();'; - $this->xmlSData[$this->xmlCount].='$this->makeTDHeader("xml","xmlAttributes");'; - if(count($attribs)>0) - $this->xmlSData[$this->xmlCount].='$this->varIsArray($this->xmlAttrib['.$this->xmlCount.']);'; - else - $this->xmlSData[$this->xmlCount].='echo " ";'; - $this->xmlSData[$this->xmlCount].='echo $this->closeTDRow();'; - $this->xmlCount++; - } - - //xml: initiated when an end tag is encountered - 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] : " "; - echo $this->closeTDRow(); - $this->makeTDHeader("xml","xmlComment"); - echo (!empty($this->xmlDData[$i])) ? $this->xmlDData[$i] : " "; - echo $this->closeTDRow(); - $this->makeTDHeader("xml","xmlChildren"); - unset($this->xmlCData[$i],$this->xmlDData[$i]); - } - echo $this->closeTDRow(); - echo ""; - $this->xmlCount=0; - } - - //xml: initiated when text between tags is encountered - function xmlCharacterData($parser,$data) { - $count=$this->xmlCount-1; - if(!empty($this->xmlCData[$count])) - $this->xmlCData[$count].=$data; - else - $this->xmlCData[$count]=$data; - } - - //xml: initiated when a comment or other miscellaneous texts is encountered - function xmlDefaultHandler($parser,$data) { - //strip '' off comments - $data=str_replace(array("<!--","-->"),"",htmlspecialchars($data)); - $count=$this->xmlCount-1; - if(!empty($this->xmlDData[$count])) - $this->xmlDData[$count].=$data; - else - $this->xmlDData[$count]=$data; - } - - function initJSandCSS() { - echo << - /* code modified from ColdFusion's cfdump code */ - 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) { - 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) { - target.style.display = (switchToState=='open') ? '' : 'none'; - } - - function dBug_toggleTable(source) { - var switchToState=dBug_toggleSource(source); - if(document.all) { - var table=source.parentElement.parentElement; - for(var i=1;i - - -SCRIPTS; - } - -} - From 9e56c718fc3e768bb948ed8698e14adea7614438 Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 22:29:59 +0200 Subject: [PATCH 14/28] psr4 2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d153e0a..29745de 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "php": ">=5.3.2" }, "autoload": { - "psr-4": {"Ospinto\\dBug": "/"} + "psr-4": {"Ospinto\\dBug": ""} } } \ No newline at end of file From fc99c949db52208232600d8f355488cbe1f93db4 Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 22:32:40 +0200 Subject: [PATCH 15/28] psr4 3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 29745de..bb6c9d0 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "php": ">=5.3.2" }, "autoload": { - "psr-4": {"Ospinto\\dBug": ""} + "psr-4": {"Ospinto\dBug": ""} } } \ No newline at end of file From bcf154b0a9a134373ca0bedf828ccefe6b8dc77c Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 22:35:10 +0200 Subject: [PATCH 16/28] back to psr0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bb6c9d0..1a33378 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "php": ">=5.3.2" }, "autoload": { - "psr-4": {"Ospinto\dBug": ""} + "psr-0": {"Ospinto\\dBug": ""} } } \ No newline at end of file From 3bd5c93427d0272160a2bf99f10c85f8055830ed Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 22:40:19 +0200 Subject: [PATCH 17/28] to psr-4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1a33378..c9f6f88 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "php": ">=5.3.2" }, "autoload": { - "psr-0": {"Ospinto\\dBug": ""} + "psr-4": {"Ospinto\\dBug\\": ""} } } \ No newline at end of file From 9cb9ff4981755b4915beade04c3a40e43ecf6dd3 Mon Sep 17 00:00:00 2001 From: sunra Date: Sat, 12 Dec 2015 22:57:32 +0200 Subject: [PATCH 18/28] psr4 2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c9f6f88..6bb7a63 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ "php": ">=5.3.2" }, "autoload": { - "psr-4": {"Ospinto\\dBug\\": ""} + "psr-4": {"Ospinto\\": ""} } } \ No newline at end of file From fc66b3f10429f09dfe364650bacdc6e8fbeac21b Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 01:12:13 +0200 Subject: [PATCH 19/28] old style constructor fixed --- dBug.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dBug.php b/dBug.php index 272b957..5e5c56d 100644 --- a/dBug.php +++ b/dBug.php @@ -68,7 +68,7 @@ class dBug { var $arrHistory = array(); //constructor - function dBug($var,$forceType="",$bCollapsed=false) { + function __construct($var,$forceType="",$bCollapsed=false) { //include js and css scripts if(!defined('BDBUGINIT')) { define("BDBUGINIT", TRUE); From 7c24da25e119b3f449cdbb77c708fdd5fcc02f76 Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 06:07:38 +0200 Subject: [PATCH 20/28] release 0.1.0 --- README.md | 10 +++++++++- composer.json | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f5ca204..3886e35 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ # dBug -- Updated for PSR-0 copmliance +- Updated for PSR-4 copmliance - created composer package +## NEW +- Updated to version from August 6th, 2012 of Ospinto's code +- move to psr-4 + +## See also +*dBug Twig Filter* - https://github.com/sunra/dbug-twig-extension +I love this way of use dBug + ## Usage diff --git a/composer.json b/composer.json index 6bb7a63..f79744b 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,12 @@ "description": "Most beautiful variable dump library for PHP (ColdFusion like style)", "keywords": ["php","dump","debug"], "homepage": "http://github.com/sunra/dBug.git", - "license": "MIT", + "license": "GPL-3.0", "authors": [ + { + "name": "Kwaku Otchere", + "email": "ospinto@hotmail.com" + }, { "name": "sunra", "email": "sunra@yandex.ru", From 0c583c466a3533f4878450e23d70ce06153767b4 Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 06:10:01 +0200 Subject: [PATCH 21/28] readme updated --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3886e35..1248b72 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,12 @@ - Updated to version from August 6th, 2012 of Ospinto's code - move to psr-4 -## See also -*dBug Twig Filter* - https://github.com/sunra/dbug-twig-extension -I love this way of use dBug - ## Usage +*I love use dBug via **Twig Filter** * - https://github.com/sunra/dbug-twig-extension + + Install via Composer. Class will be autoloaded. From ae97ed5274be2eb9abe3c70623349456bec66ace Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 06:11:00 +0200 Subject: [PATCH 22/28] readme updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1248b72..2ab6d2f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ## Usage -*I love use dBug via **Twig Filter** * - https://github.com/sunra/dbug-twig-extension +I love use dBug via **Twig Filter** - https://github.com/sunra/dbug-twig-extension Install via Composer. From b27f1e3f6eda2aa9521ff9a65c3d54a5100cd7ca Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 06:12:59 +0200 Subject: [PATCH 23/28] readme updated --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ab6d2f..d3843fa 100644 --- a/README.md +++ b/README.md @@ -9,21 +9,21 @@ ## Usage -I love use dBug via **Twig Filter** - https://github.com/sunra/dbug-twig-extension +### Twig Filter - https://github.com/sunra/dbug-twig-extension -Install via Composer. +### Install via Composer. Class will be autoloaded. -### usage +#### usage ``` php new \Ospinto\Dbug($myVariable); ``` -### Class arguments: +#### Class arguments: __construct ($var,$forceType="",$bCollapsed=false, $var_name='') From 9ee6ea224db9883d8c6f2cdcbf39509858f47db3 Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 06:13:50 +0200 Subject: [PATCH 24/28] readme updated --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d3843fa..cf8c0fa 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ ### Twig Filter - https://github.com/sunra/dbug-twig-extension +or ### Install via Composer. Class will be autoloaded. From b7bcd1c5f75ca857592b8cf95e2ab268d82e40b1 Mon Sep 17 00:00:00 2001 From: sunra Date: Sun, 13 Dec 2015 06:15:38 +0200 Subject: [PATCH 25/28] readme updated --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf8c0fa..18709f7 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ or -### Install via Composer. +### Install via Composer - https://packagist.org/packages/sunra/dbug Class will be autoloaded. From 51c474c46ac0b53d0278d3f48a5b591d90630e09 Mon Sep 17 00:00:00 2001 From: repat Date: Mon, 14 Dec 2015 20:06:08 +0100 Subject: [PATCH 26/28] fixed capital B and lower d in usage see the class name in usage example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18709f7..7307faa 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Class will be autoloaded. #### usage ``` php - new \Ospinto\Dbug($myVariable); + new \Ospinto\dBug($myVariable); ``` From c18d91da49a03693a1d3d73f44b4545d24e07f74 Mon Sep 17 00:00:00 2001 From: sunra Date: Tue, 15 Dec 2015 00:34:46 +0200 Subject: [PATCH 27/28] 0.2.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f79744b..578f655 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "sunra/dbug", - "version": "0.1.0", + "version": "0.2.0", "type": "library", "description": "Most beautiful variable dump library for PHP (ColdFusion like style)", "keywords": ["php","dump","debug"], @@ -23,4 +23,4 @@ "autoload": { "psr-4": {"Ospinto\\": ""} } -} \ No newline at end of file +} From ecd8a589dc3ee1bba84095828c222ff560bc19e5 Mon Sep 17 00:00:00 2001 From: sunra Date: Tue, 15 Dec 2015 00:37:24 +0200 Subject: [PATCH 28/28] 0.2.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 578f655..545421c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "sunra/dbug", - "version": "0.2.0", + "version": "0.2.1", "type": "library", "description": "Most beautiful variable dump library for PHP (ColdFusion like style)", "keywords": ["php","dump","debug"],