#native_company# #native_desc#
#native_cta#

Complex Object Dumping

By kjj
on December 18, 2000

Version: 1.0.1

Type: Function

Category: Other

License: Other

Description: include file for dumping complex objects in three formats: preformatted text, HTML lists, and HTML tables.

<?
if(!isset($object_dump_lib_semaphore)){
$object_dump_lib_semaphore=TRUE;

/*
object_dump.lib        version 1.0

syntax:
 object_dump(string $name, mixed $object, string $prefix="", string $type="html")
    potential front end for the other three, not really needed

 html_object_dump(string $name, mixed $object, string $prefix="")
    Dumps as a HTML list.  changing $listt and $clistt will change the type of list

 table_object_dump(string $name, mixed $object, string $prefix="")
    Dumps as a HTML table.  There are some config type things near the top
    Currently pretty ugly.

 text_object_dump(string $name, mixed $object, string $prefix="")
    Dumps as preformatted text.

  $prefix is superfulous in all but text_object_dump, but it keeps the interfaces the same


    Kyle Jerviss
    [email protected]
*/

function object_dump($name,$obj,$prefix="",$type="html"){
 if("html"==$type)$retval=html_object_dump($name,$obj,$prefix);
 if("text"==$type)$retval=text_object_dump($name,$obj,$prefix);
 if("table"==$type)$retval=table_object_dump($name,$obj,$prefix);
 return $retval;
}

function html_object_dump($name,$obj,$prefix=""){
 $listt="<UL>";
 $clistt="</UL>";
 $retval="";
 $retval.=$name;
 if(is_array($obj) OR is_object($obj)){
  $retval.=" (".gettype($obj).")";
  $retval.=$listt."";
  while(list($key,$val)=each($obj)){
   $retval.="<LI>".html_object_dump($key,$val," | ".$prefix)."</LI>";
  }
  $retval.=$clistt;
 }else{
  $retval.=" = ".$obj." (".gettype($obj).")";
 }
 return $retval;
}

function table_object_dump($name,$obj,$prefix=""){
 $size="<H2>";
 $csize="</H2>";
 $border=    "border=1 bordercolor="#000000"";
 $align=    "align="left"";
 $valign=    "valign="top"";
 $ncolor=    "bgcolor="#FF0000"";
 $tcolor=    "bgcolor="#00FF00"";
 $vcolor=    "bgcolor="#0000FF"";
 $retval="";
 $retval.="<TABLE ".$border.">n";
 $retval.="t<TR>ntt<TD rowspan=1 ".$valign." ".$align." ".$ncolor.">".$size.$name.$csize."</TD>n";
 if(is_array($obj) OR is_object($obj)){
  $retval.="tt<TD rowspan=1 ".$valign." ".$align." ".$tcolor.">(".gettype($obj).")</TD>n";
  $retval.="tt<TD rowspan=2 ".$valign." ".$align." ".$vcolor.">";
  while(list($key,$val)=each($obj)){
   $retval.=table_object_dump($key,$val," | ".$prefix);
  }
  $retval.="</TD>n";
 }else{
  $retval.="tt<TD ".$valign." ".$align." ".$tcolor.">(".gettype($obj).")</TD>n";
  $retval.="tt<TD ".$valign." ".$align." ".$vcolor.">".$obj."</TD>n";
 }
 $retval.="t</TR>n</TABLE>n";
 return $retval;
}

function text_object_dump($name,$obj,$prefix=""){
 $retval="";
 $retval.=$prefix." ".$name;
 if(is_array($obj) OR is_object($obj)){
  $retval.=" (".gettype($obj).")"."n";
  while(list($key,$val)=each($obj)){
   if(""==$prefix){
    $retval.=text_object_dump($key,$val," + ".$prefix);
   }else{
    $retval.=text_object_dump($key,$val," | ".$prefix);
   }
  }
 }else{
  $retval.=" = ".$obj." (".gettype($obj).")"."n";
 }
 return $retval;
}

}
?>