Location: PHPKode > scripts > Adump > dump/Debug.class.php
<?php
      session_start();

class Dump {
   /**
   * Dump.class.php
	*
   * A class for generating dumps from all types of variables including Objects.
   * 
   * Copyright (C) 2002 Bulent Tezcan <hide@address.com>
   * 
   * This class is a modified version of dump.class.php 
	* (written by: Daniel Jaenecke <hide@address.com>) taken from www.phpclasses.org.
   * I modified and added some functions to it. The original copy could be found at
   * http://www.phpclasses.org/browse.html/package/471.html
   * 
   * 
   *      This program is free software; you can redistribute it and/or modify
   *      it under the terms of the GNU General Public License as published by
   *      the Free Software Foundation; either version 2 of the License, or
   *      (at your option) any later version.
   * 
   *      This program is distributed in the hope that it will be useful,
   *      but WITHOUT ANY WARRANTY; without even the implied warranty of
   *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *      GNU General Public License for more details.
   * 
   *      You should have received a copy of the GNU General Public License
   *      along with this program; if not, write to the Free Software
   *      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */

   /**
   * HOW TO USE
   * ==========
   * 
   * You can assign the data you which to dump in two ways:
	*
   * 	a) when creating an object, e.g.
   * 		$d = new dump ( $nameOfTheVariable , $my_data )
   * 
   * 	b) by calling the method assignData ($name, $data)
   * 		$d = new Dump();
   * 		$d->assignData( 'mydata', $my_data );
   * 
   * The method GetHtml() will return an HTML-table representing the
   * data which has been assigned before using one of the methods mentioned
   * above. 
	*	
	*	After either a) or b) a command like
   * 		echo $d->GetHtml (); or
	*		echo $d->getHtmlFromAGivenData($someMixedVariable);
   * would output the table.
	*
	* Also you can get a PopUp Window instead of dumping it to the current page by:
	*
	*
	*	$d->dumpPopup();
	*
   * 
   * CUSTOMIZING
   * ===========
   * 
   * The output is formatted using HTML-inline-styles which are defined in the
   * properties style_key, style_value and style_type. By assigning different
   * values output may be changed easily to fit individual needs.
   * 
   * REQUIREMENTS
   * ============
   * 
   * This class needs PHP 4.2 or later to run; You should also have the dump.php file
	* in order to dump it to a Popup Window.
   * 
   */

   /**
   * styles for HTML-Output
   */
   var
   $style_key = null,
   $style_value = null,
   $style_type = null ;

   /**
   * METHODS
   */
   /**
   * public constructor Dump ( [ mixed data ] )
   * construcor; accepting data for dumping as parameter
   */
   function Dump ($name= null , $data = null)
   {
      $this->mClear = FALSE;
		$this->mPopupHeight = 500;
		$this->mPopupWidth = 600;
		$this->mRefresh = 4;

		/**
      * assign data if available
      */
      if (!is_null ($data)) {
         $this->AssignData ($name,$data);
      } 

      /**
      * set up styles for HTML-output
      */
      $this->style_key = 'font-family: sans-serif; font-size: 12px; font-weight: bold; background-color: #f0f0f0;';
      $this->style_value = 'font-family: monospace; font-size: 12px;';
      $this->style_type = 'font-family: sans-serif; font-size: 11px; color: #CC0099;';
   } 
   /**
   * public void resetData( )
   * resets the variable data, so it won't display the previously assigned data. Remember
	* we will keep displaying the previous data, as long as you wish to see.
   */
   function resetSessionData ( )
   {
		$this->mClear = TRUE;
	} 
   /**
   * public void refresh($value)
   * It will call resetSessionData after n times defined in the refresh rate.
   */
   function setRefresh($value)
   {
		$this->mRefresh = $value;
	} 
   /**
   * public void setPopupWidth( )
   * sets the popup windows width
   */
   function setPopupWidth($value)
   {
		$this->mPopupWidth = $value;
	} 
   /**
   * public void setPopupHeight( )
   * sets the popup windows Height
   */
   function setPopupHeight($value)
   {
		$this->mPopupHeight = $value;
	} 

   /**
   * public string getHtmlFromAGivenData (mixed data)
   * creates and returns an HTML-Table from a passed data
   */
   function getHtmlFromAGivenData ($data)
   {
      if (!isset ($data)) {
         return false;
      } else {
         return $this->_make_HTML_table ($data);
      } 
   } 

   /**
   * public string GetHtml ( )
   * creates and returns an HTML-Table from this->data
   */
   function getHtml ( )
   {
      if (!isset ($this->data)) {
         return false;
      } else {
         return $this->_make_HTML_table ($this->data);
      } 
   } 

   /**
   * public string dumpPopup ( )
   * creates and returns an HTML-Table from $_SESSION['__dump'] in a popup window
   */
   function dumpPopup ()
   {
		if ($this->mClear === TRUE)
			unset($_SESSION['__dump']);

		if (++$_SESSION['__refresh'] > $this->mRefresh)
		{
			unset($_SESSION['__dump']);
			$_SESSION['__refresh'] = 1;
		}

		$temp['current'] = $this->data;
		$temp['previous']= $_SESSION['__dump'];

      $_SESSION['__dump'] = $temp;

      echo '<SCRIPT>			w=window.open("dump.php","Debugging","WIDTH='.$this->mPopupWidth.',HEIGHT='.$this->mPopupHeight.',scrollbars=yes,resizable=yes");		w.focus();	</SCRIPT>';
   } 

   /**
   * public void assignData ( name_of_variable, mixed data )
   * assign data for later dump
   */
   function assignData ($name, $data)
   {
      $this->data[$name] = $data;
   } 

   /**
   * private string _make_HTML_table ( mixed data )
   */
   function _make_HTML_table ($data)
   {
      if (!is_array ($data)) {
         switch (gettype ($data)) {
            case 'string':

               return (isset ($data) && !empty ($data)) ?
               htmlentities ($data) :
               '&nbsp;' ;
               break;

            case 'boolean':

               return $data ? 'true' : 'false';

               break;

            case 'object':

               $object_data = array ('class' => get_class ($data),
                  'parent_class' => get_parent_class ($data),
                  'methods' => get_class_methods (get_class ($data)),
                  'properties' => get_object_vars ($data)

                  );

               return $this->_make_HTML_table ($object_data);

               break;

            case 'resource':

               return sprintf ('%s (%s)', $data, get_resource_type ($data));

               break;
            default:

               return $data;

               break;
         } 

      } 

      $output = '<table cellspacing="0" cellpadding="1" border="0" bgcolor="#3333CC"><tr><td><table border="0" cellpadding="1" cellspacing="1" bgcolor="#ffffff">';

      foreach ($data as $key => $value) {
         $type = substr (gettype ($data[ $key ]), 0, 3);

         $output .= sprintf ('<tr>
					<td style="%s">%s</td>
					<td style="%s">%s</td>
					<td style="%s">%s</td>
				</tr>',

            $this->style_key, $key,
            $this->style_type, $type,
            $this->style_value, $this->_make_HTML_table ($value)

            );
      } 

      $output .= '</table></td></tr></table>';

      return $output;
   } 

} 

?>
Return current item: Adump