Source for file dump.php

Documentation is available at dump.php

  1. <?php
  2.  
  3. /**
  4.  * Dumps values of the given variable, or the entire data if nothing provided
  5.  * <pre>
  6.  *  * var : the variable to display
  7.  * </pre>
  8.  * This software is provided 'as-is', without any express or implied warranty.
  9.  * In no event will the authors be held liable for any damages arising from the use of this software.
  10.  *
  11.  * This file is released under the LGPL
  12.  * "GNU Lesser General Public License"
  13.  * More information can be found here:
  14.  * {@link http://www.gnu.org/copyleft/lesser.html}
  15.  *
  16.  * @author     Jordi Boggiano <[email protected]>
  17.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  18.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  19.  * @link       http://dwoo.org/
  20.  * @version    0.9.1
  21.  * @date       2008-05-30
  22.  * @package    Dwoo
  23.  */
  24. class Dwoo_Plugin_dump extends Dwoo_Plugin
  25. {
  26.     public function process($var '$')
  27.     {
  28.         if ($var === '$'{
  29.             $var $this->dwoo->getData();
  30.             $out '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">data';
  31.         else {
  32.             $out '<div style="background:#aaa; padding:5px; margin:5px; color:#000;">dump';
  33.         }
  34.  
  35.         if (!is_array($var)) {
  36.             return $this->exportVar(''$var);
  37.         }
  38.  
  39.         $scope $this->dwoo->getScope();
  40.  
  41.         if ($var === $scope{
  42.             $out .= ' (current scope): <div style="background:#ccc;">';
  43.         else {
  44.             $out .= ':<div style="padding-left:20px;">';
  45.         }
  46.  
  47.         $out .= $this->export($var$scope);
  48.  
  49.         return $out .'</div></div>';
  50.     }
  51.  
  52.     protected function export($var$scope)
  53.     {
  54.         $out '';
  55.         foreach ($var as $i=>$v{
  56.             if (is_array($v|| (is_object($v&& $v instanceof Iterator)) {
  57.                 $out .= $i.' ('.(is_array($v'array':'object:'.get_class($v)).')';
  58.                 if ($v===$scope{
  59.                     $out .= ' (current scope):<div style="background:#ccc;padding-left:20px;">'.$this->export($v$scope).'</div>';
  60.                 else {
  61.                     $out .= ':<div style="padding-left:20px;">'.$this->export($v$scope).'</div>';
  62.                 }
  63.             else {
  64.                 $out .= $this->exportVar($i.' = '$v);
  65.             }
  66.         }
  67.         return $out;
  68.     }
  69.  
  70.     protected function exportVar($i$v)
  71.     {
  72.         if (is_string($v|| is_bool($v|| is_numeric($v)) {
  73.             return $i.htmlentities(var_export($vtrue)).'<br />';
  74.         elseif (is_null($v)) {
  75.             return $i.'null<br />';
  76.         elseif (is_object($v)) {
  77.             return $i.'object('.get_class($v).')<br />';
  78.         elseif (is_resource($v)) {
  79.             return $i.'resource('.get_resource_type($v).')<br />';
  80.         else {
  81.             return $i.htmlentities(var_export($vtrue)).'<br />';
  82.         }
  83.     }
  84. }

Documentation generated on Sun, 03 Aug 2008 15:12:27 +0200 by phpDocumentor 1.4.0