Source for file class.mpdebug.php

Documentation is available at class.mpdebug.php

  1. <?php
  2. /**
  3.  * Contains a debug class used as a helper during development.
  4.  *
  5.  * @author      Murat Purc <murat@purc.de>
  6.  * @copyright   © Murat Purc 2008
  7.  * @package     Development
  8.  * @subpackage  Debugging
  9.  */
  10.  
  11.  
  12. defined('CON_FRAMEWORK'or die('Illegal call');
  13.  
  14.  
  15. /**
  16.  * Debug class. Provides a possibility to debug variables without destroying the page
  17.  * output.
  18.  *
  19.  * If debugging is enabled, the output will be a small collapsable mpWebDebug bar
  20.  * at the top left corner of the page.
  21.  *
  22.  * Inspired by the Web Debug Toolbar of symfony Framework whith a simple way to
  23.  * provide debug informations during development.
  24.  *
  25.  * See example1.php and example2.php in delivered package.
  26.  *
  27.  * Usage:
  28.  * <code>
  29.  * // include the class file
  30.  * require_once('class.mpdebug.php');
  31.  *
  32.  * // get instance of the mpdebug class
  33.  * $mpDebug = mpDebug::getInstance();
  34.  *
  35.  * // set configuration
  36.  * $options = array(
  37.  *     'enable'                    => true,
  38.  *     'ressource_urls'            => array('/path_to_logs/error.txt'), // this is a not working exaqmple ;-)
  39.  *     'dump_super_globals'        => array('$_GET', '$_POST', '$_COOKIE', '$_SESSION'),
  40.  *     'ignore_empty_superglobals' => true,
  41.  * );
  42.  * $mpDebug->setConfig($options);
  43.  *
  44.  * $foo = 'Text';
  45.  * $mpDebug->addDebug($foo, 'Content of foo');
  46.  *
  47.  * $bar = array('win', 'nix', 'apple');
  48.  * $mpDebug->addDebug($bar, 'win, nix and apple', __FILE__, __LINE__);
  49.  *
  50.  * ...
  51.  *
  52.  * // and at the end of the page (before closing body-Tag)...
  53.  * echo $mpDebug->getResults();
  54.  * </code>
  55.  *
  56.  * @author      Murat Purc <murat@purc.de>
  57.  * @copyright   © Murat Purc 2008
  58.  * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
  59.  * @version     0.9
  60.  * @package     Development
  61.  * @subpackage  Debugging
  62.  */
  63. class mpDebug {
  64.  
  65.     /**
  66.      * Self instance
  67.      * @var  mpDebug 
  68.      */
  69.     static protected $_instance;
  70.  
  71.     /**
  72.      * Array to store dumps of variables, as follows:
  73.      * <code>
  74.      * - $_dumpCache[pos]['name']
  75.      * - $_dumpCache[pos]['value']
  76.      * - $_dumpCache[pos]['source']
  77.      * - $_dumpCache[pos]['line']
  78.      * </code>
  79.      * @var  array 
  80.      */
  81.     private $_dumpCache = array();
  82.  
  83.     /**
  84.      * Flag to activate debug
  85.      * @var  bool 
  86.      */
  87.     protected $_enable = false;
  88.  
  89.     /**
  90.      * Flag to trim document root from paths
  91.      * @var  bool 
  92.      */
  93.     private $_trimDocRoot = true;
  94.  
  95.     /**
  96.      * Document root
  97.      * @var  string 
  98.      */
  99.     private $_docRoot;
  100.  
  101.     /**
  102.      * Counter 4 added debug items
  103.      * @var  int 
  104.      */
  105.     private $_counter = 0;
  106.  
  107.     /**
  108.      * Debug links absolute from document-root, e. g. to log files or other docs.
  109.      * @var  array 
  110.      */
  111.     private $_resUrls = array();
  112.  
  113.     /**
  114.      * List of superglobals names to dump automatically.
  115.      * @var  array 
  116.      */
  117.     private $_dumpSuperglobals = array('$_GET''$_POST''$_COOKIE''$_SESSION');
  118.  
  119.     /**
  120.      * Ignore dumping of empty superglobals.
  121.      * @var  bool 
  122.      */
  123.     private $_ignoreEmptySuperglobals = false;
  124.  
  125.  
  126.     /**
  127.      * Constructor
  128.      */
  129.     protected function __construct(){
  130.         if ($this->_trimDocRoot == true{
  131.             $this->_docRoot = $_SERVER['DOCUMENT_ROOT'];
  132.             if (DIRECTORY_SEPARATOR == "\\"{
  133.                  $this->_docRoot = str_replace(DIRECTORY_SEPARATOR'/'$this->_docRoot);
  134.              }
  135.         }
  136.     }
  137.  
  138.  
  139.     /**
  140.      * Returns a instance of mpDebug (singleton implementation)
  141.      *
  142.      * @return  mpDebug 
  143.      */
  144.     public static function getInstance({
  145.         if (self::$_instance == null{
  146.             self::$_instance new mpDebug();
  147.         }
  148.         return self::$_instance;
  149.     }
  150.  
  151.  
  152.     /**
  153.      * Sets configuration
  154.      *
  155.      * @param  array  $options  Options array as follows:
  156.      *  <code>
  157.      *  // true or false to enable/disable debugging
  158.      *  $options['enable'] = true;
  159.      *
  160.      *  // Array of ressource files which will be linked at the end of debug output. You can add e. g.
  161.      *  // the HTML path to existing logfiles.
  162.      *  $options['ressource_urls'] = array('/contenido/logs/errorlog.txt', '/cms/logs/my_own_log.txt');
  163.      *
  164.      *  // Array superglobals to dump automatically, add each superglobal, but not $GLOBALS
  165.      *  $options['dump_super_globals'] = array('$_GET', '$_POST', '$_COOKIE', '$_SESSION');
  166.      *
  167.      *  // Flag to ignore dumpoutput of empty superglobals
  168.      *  $options['ignore_empty_superglobals'] = true;
  169.      *
  170.      *  // Magic word to use, if you want to overwrite $options['enable'] option. You can force debugging
  171.      *  // by using this option. In this case, you can enable it adding the parameter
  172.      *  // magic_word={my_magic_word} to the URL, e. g.
  173.      *  // http://domain.tld/mypage.php?magic_word={my_magic_word}
  174.      *  // After then debugging will be enabled for the next 1 hour (set by cookie)
  175.      *  $options['magic_word'] = 'foobar';
  176.      *
  177.      *  // Second way to overwrite option $options['enable']. Here you can define a own function, which
  178.      *  // should check, if debugging is to enable or not. The function should return a boolean value,
  179.      *  // true to enable it, or false to disable.
  180.      *  $options['user_func'] = 'myFunctionName';
  181.      *  </code>
  182.      */
  183.     public function setConfig(array $options{
  184.  
  185.         //enable/disable debugging
  186.         if (isset($options['enable'])) {
  187.             $this->_enable = (bool) $options['enable'];
  188.         }
  189.  
  190.         if (isset($options['magic_word'])){
  191.             // debug enable check with magic_word send by request
  192.             $cookieVal md5($options['magic_word']);
  193.             if (isset($_GET['magic_word']== $options['magic_word']{
  194.                 @setcookie('mpDebug_mw'$cookieValtime(3600)// enable debugging for 1 hour
  195.                 $this->_enable true;
  196.             elseif (isset($_COOKIE['mpDebug_mw']&& $_COOKIE['mpDebug_mw'== $cookieVal{
  197.                 $this->_enable true;
  198.             }
  199.         elseif (isset($options['user_func']&& is_function($options['user_func'])) {
  200.             // debug enable check with userdefined function
  201.             $this->_enable call_user_func($options['user_func']);
  202.         }
  203.  
  204.         // ressource urls
  205.         if (isset($options['ressource_urls']&& is_array($options['ressource_urls'])) {
  206.             $this->_resUrls $options['ressource_urls'];
  207.         }
  208.  
  209.         // auto dump of globals or superglobals
  210.         if (isset($options['dump_super_globals']&& is_array($options['dump_super_globals'])) {
  211.             $this->_dumpSuperglobals $options['dump_super_globals'];
  212.         }
  213.  
  214.         // ignore dumping of empty superglobals
  215.         if (isset($options['ignore_empty_superglobals'])) {
  216.             $this->_ignoreEmptySuperglobals = (bool) $options['ignore_empty_superglobals'];
  217.         }
  218.  
  219.     }
  220.  
  221.  
  222.     /**
  223.      * Wrapper 4 var_dump function. Dumps content of passed variable.
  224.      *
  225.      * @param   mixed   $var       Variable 2 dump content
  226.      * @param   string  $source    Name of source
  227.      * @param   bool    $print     Flag to print out dump result
  228.      * @param   bool    $decorate  Flag to decorate the dump result with pre-Tag
  229.      * @return  mixed            Content of var, if its not to print
  230.      */
  231.     public function vdump($var$source=''$print=true$decorate=false{
  232.         if ($this->_enable == false{
  233.             return;
  234.         }
  235.  
  236.         if ($source !== ''$source .= ":\n"}
  237.         ob_start();
  238.         print "\n".$source."\n";
  239.         print_r($var);
  240.         print "\n";
  241.         $dump ob_get_contents();
  242.         ob_end_clean();
  243.  
  244.         if ($decorate{
  245.             $dump '<pre>' $dump '</pre>';
  246.         }
  247.  
  248.         if ($print == true{
  249.             print $dump;
  250.         else {
  251.             return $dump;
  252.         }
  253.     }
  254.  
  255.  
  256.     /**
  257.      * Adds a varible dump.
  258.      *
  259.      * @param  mixed   $var     Variable 2 dump
  260.      * @param  string  $name    Additional info like name or whatever you wan't do describe the passed variable
  261.      * @param  string  $source  Filename (e. g. __FILE__) to specify the location of caller
  262.      * @param  string  $line    Line (e. g. __LINE__) to specifiy the line number
  263.      */
  264.     public function addVdump($var$name$source=null$line=null{
  265.         if ($this->_enable == false{
  266.             return;
  267.         }
  268.  
  269.         $this->_addDebugValue($this->vdump($var$sourcefalse)$name$source$line);
  270.     }
  271.  
  272.  
  273.     /**
  274.      * Adds a varible dump, does the same as addVdump().
  275.      *
  276.      * @param  mixed   $var     Variable 2 dump
  277.      * @param  string  $name    Additional info like name or whatever you wan't do describe the passed variable
  278.      * @param  string  $source  Filename (e. g. __FILE__) to specify the location of caller
  279.      * @param  string  $line    Line (e. g. __LINE__) to specifiy the line number
  280.      */
  281.     public function addDebug($var$name$source=null$line=null){
  282.         if ($this->_enable == false{
  283.             return;
  284.         }
  285.  
  286.         $this->_addDebugValue($var$name$source$line);
  287.     }
  288.  
  289.  
  290.     /**
  291.      * Adds passed variable to the debug cache.
  292.      *
  293.      * @param   mixed   $var     Variable 2 dump
  294.      * @param   string  $name    Additional info like name or whatever you wan't do describe the passed variable
  295.      * @param   string  $source  Filename (e. g. __FILE__) to specify the location of caller
  296.      * @param   string  $line    Line (e. g. __LINE__) to specifiy the line number
  297.      * @access  private
  298.      */
  299.     private function _addDebugValue($var$name$source$line){
  300.         if ($this->_enable == false{
  301.             return;
  302.         }
  303.         if ($source !== null{
  304.             if ($this->_trimDocRoot == true{
  305.                 if (DIRECTORY_SEPARATOR == "\\"{
  306.                     $source str_replace(DIRECTORY_SEPARATOR'/'$source);
  307.                 }
  308.                 $source str_replace($this->_docRoot''$source);
  309.             }
  310.         }
  311.         $arr['var']    $var;
  312.         $arr['name']   $name;
  313.         $arr['source'$source;
  314.         $arr['line']   $line;
  315.  
  316.         $this->_dumpCache[$arr;
  317.     }
  318.  
  319.  
  320.     /**
  321.      * Main method to get the mpWebDebug Bar.
  322.      *
  323.      * Returns or prints the mpWebDebug Bar depending on state of $print
  324.      *
  325.      * @param  bool  $print  Flag to print the mpWebDebug Bar
  326.      * @return  mixed  The mpWebDebug Bar if $print is set to false or nothing
  327.      */
  328.     public function getResults($print=true{
  329.         if ($this->_enable == false{
  330.             return;
  331.         }
  332.  
  333.         $dumpOutput  '';
  334.         $dumpOutput .= $this->_startOutput();
  335.  
  336.         // dump superglobals
  337.         foreach ($this->_dumpSuperglobals as $p => $name{
  338.             $dumpSG true;
  339.             $SG $this->_getSuperGlobal($name);
  340.             if ($this->_ignoreEmptySuperglobals{
  341.                 if ((is_array($SG&& count($SG== 0|| !isset($SG|| empty($SG)) {
  342.                     $dumpSG false;
  343.                 }
  344.             }
  345.             if ($dumpSG{
  346.                 $dumpOutput .= $this->_contentOutput($name$SG);
  347.             }
  348.         }
  349.  
  350.         // dump cache
  351.         foreach ($this->_dumpCache as $p => $v{
  352.             $info '';
  353.             if ($v['source'!== null{
  354.                 $info .= 'source: ' $v['source'"\n";
  355.             }
  356.             if ($v['line'!== null{
  357.                 $info .= 'line: ' $v['line'"\n";
  358.             }
  359.             $dumpOutput .= $this->_contentOutput($v['name']$v['var']$info);
  360.         }
  361.  
  362.         // add ressource links
  363.         $dumpOutput .= $this->_getRessourceLinks();
  364.         $dumpOutput .= '
  365. <span class="info"><br />
  366.     NOTE: This debug output should be visible only on dev environment<br />
  367.     &copy; Murat Purc 2008 &bull; <a href="http://www.purc.de/">www.purc.de</a>
  368. </span>';
  369.         $dumpOutput .= $this->_endOutput();
  370.  
  371.         if ($print == true{
  372.             print $dumpOutput;
  373.         else {
  374.             return $dumpOutput;
  375.         }
  376.     }
  377.  
  378.  
  379.     /**
  380.      * Decorates given data with a html comment and returns it back or prints it out.
  381.      *
  382.      * @param   string  $content  Data to decorate with comment
  383.      * @param   bool    $print    Flag to print the result
  384.      * @return  mixed             The composed result or nothing if is to print
  385.      */
  386.     public function comment($content$print=true){
  387.         if ($this->_enable == false{
  388.             return;
  389.         }
  390.  
  391.         $comment "\n<!-- " $content " -->\n";
  392.         if ($print == true{
  393.             print $comment;
  394.         else {
  395.             return $comment;
  396.         }
  397.     }
  398.  
  399.  
  400.     /**
  401.      * Returns the code (CSS-/ and JavaScript part) for the mpDebugBar, which can be placed inside
  402.      * the head-Tag.
  403.      *
  404.      * Prevents multiple delivering of the code using a static variable. Only the first call will
  405.      * return the code.
  406.      *
  407.      * @return  string  CSS-/JS-Code of mpWebDebug bar
  408.      */
  409.     public function getCssJsCode({
  410.         static $alreadyDelivered;
  411.  
  412.         if (isset($alreadyDelivered)) {
  413.             // code for head tag is to deliver once, and it was already delivered, return empty string
  414.             return '';
  415.         }
  416.  
  417.         $alreadyDelivered true;
  418.  
  419.         $code '
  420. <style type="text/css"><!--
  421. #mpWebDebug {position:absolute;z-index:1000;width:100%;right:0;top:0;font-size:12px;font-family:arial;text-align:left;}
  422. #mpWebDebug #webDebugAnchorBox {padding:0.2em;background:transparent;}
  423. #mpWebDebug .anchor {font-weight:bold;font-size:0.8em;color:#52bd22;margin:0;padding:0.3em;background:#575555;}
  424. #mpWebDebug .anchor a {font-weight:bold;font-family:arial;color:#52bd22;}
  425. #mpWebDebug #webDebugBox {margin-top:1.3em;padding:5px;position:absolute;left:0;top:0;background-color:#dadada;border:1px black solid;width:99%;overflow:auto;}
  426. #mpWebDebug .outputItemName {margin:0.3em 0; background:#cacaca;}
  427. #mpWebDebug .outputItemName a, #mpWebDebug .outputItemName a:hover {display:block;font-size:9pt;font-family:arial;font-weight:bold;color:black; background:transparent;}
  428. #mpWebDebug .outputItemInfo {text-decoration:underline;}
  429. #mpWebDebug .outputItemValue {padding-left:0.5em;color:#000;}
  430. #mpWebDebug .notVisible {display:none;}
  431. #mpWebDebug .info {color:#007f46;font-size:11px;}
  432. #mpWebDebug pre {margin:0;color:#000;}
  433. // --></style>
  434. <script type="text/javascript"><!-- // <![CDATA[
  435. var mpWebDebugger = {
  436.     aToggle: new Array(),
  437.     toggle: function(id){
  438.         var displayVal;
  439.         if (typeof(this.aToggle[id]) == "undefined") {
  440.             displayVal = "block";
  441.         } else {
  442.             displayVal = (this.aToggle[id] == "block") ? "none" : "block";
  443.         }
  444.         try{
  445.             document.getElementById(id).style.display = displayVal;
  446.             this.aToggle[id] = displayVal;
  447.         } catch(e) {/*alert(e);*/}
  448.     }
  449. }
  450. //]]> --></script>
  451. ';
  452.         return $code;
  453.  
  454.     }
  455.  
  456.  
  457.     /**
  458.      * Returns the mpWebDebug bar header.
  459.      *
  460.      * @return  string  Code of the mpWebDebug bar, either with or without CSS/JavaScript code block.
  461.      */
  462.     private function _startOutput(){
  463.  
  464.         // get head code (css/js)
  465.         $out $this->getCssJsCode();
  466.  
  467.         $out .= '
  468. <div id="mpWebDebug">
  469. <div id="webDebugAnchorBox"><span class="anchor">
  470.     <a href="javascript:void(0);" onclick="mpWebDebugger.toggle(\'webDebugBox\');return false;">DEBUG</a>
  471. </span></div>
  472. <div id="webDebugBox" class="notVisible">
  473. <div id="jsDebugBox" style="display:none;">
  474. <div class="outputItemName">
  475.     <a href="javascript:void(0);" onclick="mpWebDebugger.toggle(\'jsDebug\');return false;">&diams; JavaScript</a>
  476. </div>
  477. <div id="jsDebug" class="notVisible"></div>
  478. </div>
  479. ';
  480.         return $out;
  481.     }
  482.  
  483.  
  484.     /**
  485.      * Prints the content of passed debug item, depending on its type (array, object, string)
  486.      *
  487.      * @param   string  $name  Name of the variable
  488.      * @param   mixed   $var   The variable itself
  489.      * @param   string  $info  Info about the variable
  490.      * @return  string  Container with debug info about the variable
  491.      */
  492.     private function _contentOutput($name$var$info=null){
  493.         $id $this->_nextId();
  494.  
  495.         if ($info !== null{
  496.             $info_item '<div class="outputItemInfo">' str_replace("\n""<br />\n"$info'</div>';
  497.         else {
  498.             $info_item '';
  499.         }
  500.         $out '
  501. <div class="outputItemName">
  502.     <a href="javascript:void(0);" onclick="mpWebDebugger.toggle(\'' $id '\');return false;">&diams; '.$name.'</a>
  503. </div>
  504. <div id="'.$id.'" class="outputItemValue notVisible">
  505. $info_item '
  506. <pre>';
  507.  
  508.         if (is_array($var)) {
  509.             $out .= $this->_dumpVar($var);
  510.         elseif (is_object($var)) {
  511.             $out .= $this->_dumpVar($var);
  512.         elseif (is_string($var&& !empty($var)) {
  513.             $out .= $name ' = ' htmlspecialchars($var);
  514.         elseif (is_null($var)) {
  515.             $out .= $name ' = is_null';
  516.         elseif (empty($var)) {
  517.             $out .= $name ' = empty';
  518.         elseif (!isset($var)) {
  519.             $out .= $name ' = !isset';
  520.         else {
  521.             $out .= $name ' = ' $var;
  522.         }
  523.  
  524.         $out .= '</pre>
  525. </div>
  526. ';
  527.         return $out;
  528.     }
  529.  
  530.  
  531.     /**
  532.      * Creates list of linked ressource files. The result will be added to mpWebDebug.
  533.      *
  534.      * @return  string 
  535.      */
  536.     private function _getRessourceLinks({
  537.         if (!is_array($this->_resUrls)) {
  538.             return;
  539.         }
  540.         $reslinks '';
  541.         foreach ($this->_resUrls as $p => $url{
  542.             if (is_readable($this->_docRoot $url)) {
  543.                 $reslinks .= '
  544.     <li><a href="' $url '" onclick="window.open(this.href);return false;">' $url '</a></li>
  545. ';
  546.             }
  547.         }
  548.         if ($reslinks !== ''{
  549.             $id $this->_nextId();
  550.             $reslinks '
  551. <div class="outputItemName">
  552.     <a href="javascript:void(0);" onclick="mpWebDebugger.toggle(\'' $id'\');return false;">&diams; Ressource Links</a>
  553. </div>
  554. <div id="' $id '" class="notVisible">
  555.     <ul style="padding:0;">
  556.     ' $reslinks '
  557.     </ul>
  558. </div>
  559. ';
  560.         }
  561.         return $reslinks;
  562.     }
  563.  
  564.  
  565.     /**
  566.      * Returns the footer of mpWebDebug
  567.      *
  568.      * @return  string 
  569.      */
  570.     private function _endOutput(){
  571.         $out '
  572. </div>
  573. </div>
  574. ';
  575.         return $out;
  576.     }
  577.  
  578.  
  579.     /**
  580.      * Dumps passed variable.
  581.      *
  582.      * @param   mixed   $var  Variable to dump content
  583.      * @return  string  Content
  584.      */
  585.     private function _dumpVar(&$var){
  586.         $out '';
  587.         ob_start();
  588.         print_r($var);
  589.         $varDump ob_get_contents();
  590.         ob_end_clean();
  591.         $out .= htmlspecialchars($varDump);
  592.         $this->_prepareDumpOutput($out);
  593.         return $out;
  594.     }
  595.  
  596.  
  597.     /**
  598.      * Prepares data dump for output. Clears some white space characters and line endings to get an
  599.      * compact an more readable result.
  600.      *
  601.      * @param   string  $dumpOutput  Output of var_dump()
  602.      */
  603.     private function _prepareDumpOutput(&$dumpOutput){
  604.         $dumpOutput preg_replace("/(Array\n)([\s{1,*}]*)(\()/"'Array ('$dumpOutput);
  605.         $dumpOutput preg_replace("/(Array\(\n)([\s{1,*}]*)(\))/"'Array ()'$dumpOutput);
  606.         $dumpOutput preg_replace("/(Object\n)([\s{1,*}]*)(\()/"'Object ('$dumpOutput);
  607.         $dumpOutput preg_replace("/(Object\(\n)([\s{1,*}]*)(\))/"'Object ()'$dumpOutput);
  608.     }
  609.  
  610.  
  611.     /**
  612.      * Returns the Superglobal variable by name. Provides a precheck of superglobal
  613.      * size to prevend debugging variables having several MB. e. g. $_POST.
  614.      *
  615.      * Does not support the return of $GLOBALS. This variable contains since
  616.      * PHP 5 several cross references, therefore a dump will result in crossing
  617.      * memory limit or script timeout.
  618.      *
  619.      * @param   string  $name  Name of superglobal
  620.      * @return  mixed   Content of superglobal or a message or null
  621.      */
  622.     private function _getSuperGlobal($name{
  623.         switch ($name{
  624.             case '$_GET':
  625.                 return $_GET;
  626.                 break;
  627.             case '$_POST':
  628.                 // simple check of post size
  629.                 if ($sizeKB $this->_superGlobalTooBig($_POST)) {
  630.                     // content of _POST is > 512 KB
  631.                     return 'Content of POST seems to be big, approximate calculated size is ' $sizeKB ' KB';
  632.                 }
  633.                 return $_POST;
  634.                 break;
  635.             case '$_REQUEST':
  636.                 return $_REQUEST;
  637.                 break;
  638.             case '$_COOKIE':
  639.                 return $_COOKIE;
  640.                 break;
  641.             case '$_SESSION':
  642.                 // simple check of session size
  643.                 if ($sizeKB $this->_superGlobalTooBig($_SESSION)) {
  644.                     // content of _SESSION is > 512 KB
  645.                     return 'Content of SESSION seems to be big, approximate calculated size is ' $sizeKB ' KB';
  646.                 }
  647.                 return $_SESSION;
  648.                 break;
  649.             case '$_FILES':
  650.                 return $_FILES;
  651.                 break;
  652.             case '$_SERVER':
  653.                 return $_SERVER;
  654.                 break;
  655.             case '$_ENV':
  656.                 return $_ENV;
  657.                 break;
  658.             default:
  659.                 return null;
  660.                 break;
  661.         }
  662.     }
  663.  
  664.  
  665.     /**
  666.      * Returns approximate size of superglobal in kb if size is > 512 kb or false
  667.      *
  668.      * @param   mixed  $sglobal 
  669.      * @return  mixed  Size in kb or false
  670.      */
  671.     private function _superGlobalTooBig(&$sglobal{
  672.         // simple check of variable size
  673.         ob_start();
  674.         print_r($sglobal);
  675.         $dump ob_get_contents();
  676.         ob_end_clean();
  677.         if (strlen($dump524288{
  678.             return ceil((strlen($dump1024));
  679.         else {
  680.             return false;
  681.         }
  682.     }
  683.  
  684.     /**
  685.      * Creates a unique id used as id-Attribute for HTML elements using timer and internal counter.
  686.      *
  687.      * @return  string  Generated id
  688.      */
  689.     private function _nextId(){
  690.         return 'id' time('_' $this->_counter++;
  691.     }
  692.  
  693. }
  694.  
  695.  
  696. /**
  697.  * Contenido debug class, extends mpDebug and adds logging feature by using a wrapper for
  698.  * <code>
  699.  * DebuggerFactory::getDebugger('file')->show($var, $msg);
  700.  * </code>
  701.  *
  702.  * @author      Murat Purc <murat@purc.de>
  703.  * @copyright   © Murat Purc 2008
  704.  * @license     http://www.gnu.org/licenses/gpl-2.0.html - GNU General Public License, version 2
  705.  * @version     0.1
  706.  * @package     Contenido
  707.  * @subpackage  Debugging
  708.  */
  709. class Contenido_mpDebug extends mpDebug {
  710.  
  711.     /**
  712.      * Returns a instance of Contenido_mpDebug (singleton implementation)
  713.      *
  714.      * @return  Contenido_mpDebug 
  715.      */
  716.     public static function getInstance({
  717.         if (parent::$_instance == null{
  718.             cInclude('classes''Debug/DebuggerFactory.class.php');
  719.             parent::$_instance new Contenido_mpDebug();
  720.         }
  721.         return parent::$_instance;
  722.     }
  723.  
  724.  
  725.     /**
  726.      * Wrapper for logging a debug message.
  727.      *
  728.      * @param  mixed  $var   Variable to log content
  729.      * @param  string  $msg  Message to describe the variable
  730.      */
  731.     public function log($var$msg=''{
  732.         if ($this->_enable == false{
  733.             return;
  734.         }
  735.         DebuggerFactory::getDebugger('file')->show($var$msg);
  736.     }
  737.  
  738. }

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