[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/log/src/ -> lmbBacktrace.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  /**

  11   * class lmbBacktrace.

  12   *

  13   * @package log

  14   * @version $Id$

  15   */
  16  class lmbBacktrace
  17  {
  18    protected $backtrace = array();
  19  
  20    function __construct($limit_or_backtrace = null, $limit_or_offset = null, $offset = 0)
  21    {
  22      if(is_array($limit_or_backtrace))
  23      {
  24        $this->backtrace = $limit_or_backtrace;
  25        $limit = $limit_or_offset;
  26      }
  27      else
  28      {
  29        $this->backtrace = debug_backtrace();
  30        $limit = $limit_or_backtrace;
  31        $offset = (int)$limit_or_offset;
  32      }
  33  
  34      //we skip this function call also

  35      for($i=0; $i<($offset+1); $i++)
  36        array_shift($this->backtrace);
  37  
  38      if(!is_null($limit))
  39        $this->backtrace = array_splice($this->backtrace, 0, $limit);
  40    }
  41  
  42    function get()
  43    {
  44      return $this->backtrace;
  45    }
  46  
  47    function getContext()
  48    {
  49      reurn (sizeof($this->backtrace)) ? $this->backtrace[0] : '';
  50    }
  51  
  52    function toString()
  53    {
  54      $trace_string = '';
  55  
  56      foreach($this->backtrace as $item)
  57      {
  58        $trace_string .= '* ';
  59        $trace_string .= $this->_formatBacktraceItem($item) . "\n";
  60      }
  61      return $trace_string;
  62    }
  63  
  64    function _formatBacktraceItem($item)
  65    {
  66      $trace_string = '';
  67  
  68      if(isset($item['class']))
  69      {
  70        $trace_string .= $item['class'];
  71        $trace_string .= "::";
  72      }
  73  
  74      if(isset($item['function']))
  75      {
  76        $trace_string .= $item['function'];
  77        $trace_string .= "(";
  78      }
  79  
  80      if(isset($item['args']))
  81      {
  82        $sep = '';
  83        foreach($item['args'] as $arg)
  84        {
  85          $trace_string .= $sep;
  86          $sep = ', ';
  87  
  88          if(is_null($arg))
  89            $trace_string .= 'NULL';
  90          elseif(is_array($arg))
  91            $trace_string .= 'ARRAY[' . sizeof($arg) . ']';
  92          elseif(is_object($arg))
  93            $trace_string .= 'OBJECT:' . get_class($arg);
  94          elseif(is_bool($arg))
  95            $trace_string .= $arg ? 'TRUE' : 'FALSE';
  96          else
  97          {
  98            $trace_string .= '"';
  99            $trace_string .= htmlspecialchars(substr((string) @$arg, 0, 100));
 100  
 101            if(strlen($arg) > 100)
 102              $trace_string .= '...';
 103  
 104            $trace_string .= '"';
 105          }
 106        }
 107      }
 108  
 109      if(isset($item['function']))
 110      {
 111        $trace_string .= ")";
 112      }
 113  
 114      if(isset($item['file']))
 115      {
 116        $trace_string .= ' in "' . $item['file'] . '"';
 117        $trace_string .= " line ";
 118        $trace_string .= $item['line'];
 119      }
 120  
 121      return $trace_string;
 122    }
 123  }
 124  
 125  ?>


Generated: Thu Oct 16 04:42:25 2008 Cross-referenced by PHPXref 0.7