Class mpDebug

Description

Debug class. Provides a possibility to debug variables without destroying the page output.

If debugging is enabled, the output will be a small collapsable mpWebDebug bar at the top left corner of the page.

Inspired by the Web Debug Toolbar of symfony Framework whith a simple way to provide debug informations during development.

See example1.php and example2.php in delivered package.

Usage:

  1.  // include the class file
  2.  require_once('class.mpdebug.php');
  3.  
  4.  // get instance of the mpdebug class
  5.  $mpDebug mpDebug::getInstance();
  6.  
  7.  // set configuration
  8.  $options array(
  9.      'enable'                    => true,
  10.      'ressource_urls'            => array('/path_to_logs/error.txt')// this is a not working exaqmple ;-)
  11.      'dump_super_globals'        => array('$_GET''$_POST''$_COOKIE''$_SESSION'),
  12.      'ignore_empty_superglobals' => true,
  13.  );
  14.  $mpDebug->setConfig($options);
  15.  
  16.  $foo 'Text';
  17.  $mpDebug->addDebug($foo'Content of foo');
  18.  
  19.  $bar array('win''nix''apple');
  20.  $mpDebug->addDebug($bar'win, nix and apple'__FILE____LINE__);
  21.  
  22.  ...
  23.  
  24.  // and at the end of the page (before closing body-Tag)...
  25.  echo $mpDebug->getResults();

Located in /contenido/classes/mp/class.mpdebug.php (line 63)


	
			
Direct descendents
Class Description
 class Contenido_mpDebug Contenido debug class, extends mpDebug and adds logging feature by using a wrapper for
Variable Summary
Method Summary
 static mpDebug getInstance ()
 mpDebug __construct ()
 void addDebug (mixed $var, string $name, [string $source = null], [string $line = null])
 void addVdump (mixed $var, string $name, [string $source = null], [string $line = null])
 mixed comment (string $content, [bool $print = true])
 string getCssJsCode ()
 mixed getResults ([bool $print = true])
 void setConfig ( $options)
 mixed vdump (mixed $var, [string $source = ''], [bool $print = true], [bool $decorate = false])
 void _addDebugValue (mixed $var, string $name, string $source, string $line)
 string _contentOutput (string $name, mixed $var, [string $info = null])
 string _dumpVar ( &$var, mixed $var)
 string _endOutput ()
 string _getRessourceLinks ()
 mixed _getSuperGlobal (string $name)
 string _nextId ()
 void _prepareDumpOutput ( &$dumpOutput, string $dumpOutput)
 string _startOutput ()
 mixed _superGlobalTooBig ( &$sglobal, mixed $sglobal)
Variables
static mpDebug $_instance (line 69)

Self instance

  • access: protected
int $_counter = 0 (line 105)

Counter 4 added debug items

  • access: private
string $_docRoot (line 99)

Document root

  • access: private
array $_dumpCache = array() (line 81)

Array to store dumps of variables, as follows:

  1.  - $_dumpCache[pos]['name']
  2.  - $_dumpCache[pos]['value']
  3.  - $_dumpCache[pos]['source']
  4.  - $_dumpCache[pos]['line']

  • access: private
array $_dumpSuperglobals = array('$_GET', '$_POST', '$_COOKIE', '$_SESSION') (line 117)

List of superglobals names to dump automatically.

  • access: private
bool $_enable = false (line 87)

Flag to activate debug

  • access: protected
bool $_ignoreEmptySuperglobals = false (line 123)

Ignore dumping of empty superglobals.

  • access: private
array $_resUrls = array() (line 111)

Debug links absolute from document-root, e. g. to log files or other docs.

  • access: private
bool $_trimDocRoot = true (line 93)

Flag to trim document root from paths

  • access: private
Methods
static getInstance (line 144)

Returns a instance of mpDebug (singleton implementation)

  • access: public
mpDebug getInstance ()

Redefined in descendants as:
Constructor __construct (line 129)

Constructor

  • access: protected
mpDebug __construct ()
addDebug (line 281)

Adds a varible dump, does the same as addVdump().

  • access: public
void addDebug (mixed $var, string $name, [string $source = null], [string $line = null])
  • mixed $var: Variable 2 dump
  • string $name: Additional info like name or whatever you wan't do describe the passed variable
  • string $source: Filename (e. g. __FILE__) to specify the location of caller
  • string $line: Line (e. g. __LINE__) to specifiy the line number
addVdump (line 264)

Adds a varible dump.

  • access: public
void addVdump (mixed $var, string $name, [string $source = null], [string $line = null])
  • mixed $var: Variable 2 dump
  • string $name: Additional info like name or whatever you wan't do describe the passed variable
  • string $source: Filename (e. g. __FILE__) to specify the location of caller
  • string $line: Line (e. g. __LINE__) to specifiy the line number
comment (line 386)

Decorates given data with a html comment and returns it back or prints it out.

  • return: The composed result or nothing if is to print
  • access: public
mixed comment (string $content, [bool $print = true])
  • string $content: Data to decorate with comment
  • bool $print: Flag to print the result
getCssJsCode (line 409)

Returns the code (CSS-/ and JavaScript part) for the mpDebugBar, which can be placed inside the head-Tag.

Prevents multiple delivering of the code using a static variable. Only the first call will return the code.

  • return: CSS-/JS-Code of mpWebDebug bar
  • access: public
string getCssJsCode ()
getResults (line 328)

Main method to get the mpWebDebug Bar.

Returns or prints the mpWebDebug Bar depending on state of $print

  • return: The mpWebDebug Bar if $print is set to false or nothing
  • access: public
mixed getResults ([bool $print = true])
  • bool $print: Flag to print the mpWebDebug Bar
setConfig (line 183)

Sets configuration

  • access: public
void setConfig ( $options)
  • array $options: Options array as follows:
    1.  // true or false to enable/disable debugging
    2.  $options['enable'true;
    3.  
    4.  // Array of ressource files which will be linked at the end of debug output. You can add e. g.
    5.  // the HTML path to existing logfiles.
    6.  $options['ressource_urls'array('/contenido/logs/errorlog.txt''/cms/logs/my_own_log.txt');
    7.  
    8.  // Array superglobals to dump automatically, add each superglobal, but not $GLOBALS
    9.  $options['dump_super_globals'array('$_GET''$_POST''$_COOKIE''$_SESSION');
    10.  
    11.  // Flag to ignore dumpoutput of empty superglobals
    12.  $options['ignore_empty_superglobals'true;
    13.  
    14.  // Magic word to use, if you want to overwrite $options['enable'] option. You can force debugging
    15.  // by using this option. In this case, you can enable it adding the parameter
    16.  // magic_word={my_magic_word} to the URL, e. g.
    17.  // http://domain.tld/mypage.php?magic_word={my_magic_word}
    18.  // After then debugging will be enabled for the next 1 hour (set by cookie)
    19.  $options['magic_word''foobar';
    20.  
    21.  // Second way to overwrite option $options['enable']. Here you can define a own function, which
    22.  // should check, if debugging is to enable or not. The function should return a boolean value,
    23.  // true to enable it, or false to disable.
    24.  $options['user_func''myFunctionName';
vdump (line 231)

Wrapper 4 var_dump function. Dumps content of passed variable.

  • return: Content of var, if its not to print
  • access: public
mixed vdump (mixed $var, [string $source = ''], [bool $print = true], [bool $decorate = false])
  • mixed $var: Variable 2 dump content
  • string $source: Name of source
  • bool $print: Flag to print out dump result
  • bool $decorate: Flag to decorate the dump result with pre-Tag
_addDebugValue (line 299)

Adds passed variable to the debug cache.

  • access: private
void _addDebugValue (mixed $var, string $name, string $source, string $line)
  • mixed $var: Variable 2 dump
  • string $name: Additional info like name or whatever you wan't do describe the passed variable
  • string $source: Filename (e. g. __FILE__) to specify the location of caller
  • string $line: Line (e. g. __LINE__) to specifiy the line number
_contentOutput (line 492)

Prints the content of passed debug item, depending on its type (array, object, string)

  • return: Container with debug info about the variable
  • access: private
string _contentOutput (string $name, mixed $var, [string $info = null])
  • string $name: Name of the variable
  • mixed $var: The variable itself
  • string $info: Info about the variable
_dumpVar (line 585)

Dumps passed variable.

  • return: Content
  • access: private
string _dumpVar ( &$var, mixed $var)
  • mixed $var: Variable to dump content
  • &$var
_endOutput (line 570)

Returns the footer of mpWebDebug

  • access: private
string _endOutput ()
_getRessourceLinks (line 536)

Creates list of linked ressource files. The result will be added to mpWebDebug.

  • access: private
string _getRessourceLinks ()
_getSuperGlobal (line 622)

Returns the Superglobal variable by name. Provides a precheck of superglobal size to prevend debugging variables having several MB. e. g. $_POST.

Does not support the return of $GLOBALS. This variable contains since PHP 5 several cross references, therefore a dump will result in crossing memory limit or script timeout.

  • return: Content of superglobal or a message or null
  • access: private
mixed _getSuperGlobal (string $name)
  • string $name: Name of superglobal
_nextId (line 689)

Creates a unique id used as id-Attribute for HTML elements using timer and internal counter.

  • return: Generated id
  • access: private
string _nextId ()
_prepareDumpOutput (line 603)

Prepares data dump for output. Clears some white space characters and line endings to get an compact an more readable result.

  • access: private
void _prepareDumpOutput ( &$dumpOutput, string $dumpOutput)
  • string $dumpOutput: Output of var_dump()
  • &$dumpOutput
_startOutput (line 462)

Returns the mpWebDebug bar header.

  • return: Code of the mpWebDebug bar, either with or without CSS/JavaScript code block.
  • access: private
string _startOutput ()
_superGlobalTooBig (line 671)

Returns approximate size of superglobal in kb if size is > 512 kb or false

  • return: Size in kb or false
  • access: private
mixed _superGlobalTooBig ( &$sglobal, mixed $sglobal)
  • mixed $sglobal
  • &$sglobal

Documentation generated on Sun, 08 Feb 2009 22:00:46 +0100 by phpDocumentor 1.4.1