[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/core/src/exception/ -> lmbException.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 lmbException.

  12   *

  13   * @package core

  14   * @version $Id: lmbException.class.php 5945 2007-06-06 08:31:43Z pachanga $

  15   */
  16  class lmbException extends Exception
  17  {
  18    protected $params = array();
  19  
  20    function __construct($message, $params = array(), $code = 0)
  21    {
  22      if(is_array($params) && sizeof($params))
  23      {
  24        $this->params = $params;
  25        $message .= "\n[params: " . var_export($params, true) . "]\n";
  26      }
  27  
  28      $this->backtrace = debug_backtrace();
  29      parent :: __construct($message, $code);
  30    }
  31  
  32    function getParams()
  33    {
  34      return $this->params;
  35    }
  36    
  37    function getParam($name)
  38    {
  39      if(isset($this->params[$name]))
  40        return $this->params[$name];
  41    }
  42  
  43    function getNiceTraceAsString()
  44    {
  45      $html = php_sapi_name() != 'cli';
  46  
  47      $str = '';
  48      foreach($this->backtrace as $bc)
  49      {
  50        if(isset($bc['class']))
  51        {
  52          $s = ($html ? "<b>%s</b>" : "%s") . "::";
  53          $str .= sprintf($s, $bc['class']);
  54        }
  55  
  56        if (isset($bc['function']))
  57        {
  58          $s = ($html ? "<b>%s</b>" : "%s");
  59          $str .= sprintf($s, $bc['function']);
  60        }
  61  
  62        $str .= ' (';
  63        if(isset($bc['args']))
  64        {
  65          foreach($bc['args'] as $arg)
  66          {
  67            $s = ($html ? "<i>%s</i>, " : "%s, ");
  68            $type = gettype($arg);
  69  
  70            if($type == "string")
  71              $str .= sprintf($s, '"' . preg_replace('~^(.{150})(.*)$~', '$1...', $arg) . '"');
  72            elseif($type == "object")
  73              $str .= sprintf($s, get_class($arg));
  74            elseif($type == "array")
  75            {
  76              $arr = array();
  77              foreach($arg as $key => $value)
  78                $arr[] = "[$key] => $value";
  79  
  80              $str .= sprintf($s, implode(',', $arr));
  81            }
  82            elseif($type == "integer" || $type == "float")
  83              $str .= sprintf($s, $arg);
  84            else
  85              $str .= sprintf($s, $type);
  86          }
  87          $str = substr($str, 0, -2);
  88        }
  89  
  90        $str .= ')';
  91        $str .= ': ';
  92        $str .= '[ ';
  93        if (isset($bc['file'])) {
  94          $dir = substr(dirname($bc['file']), strrpos(dirname($bc['file']), '/') + 1);
  95          $file = basename($bc['file']);
  96          if ($html) $str .= "<a href=\"file:/" . $bc['file'] . "\">";
  97          $str .= $dir . '/' . $file;
  98          if ($html) $str .= "</a>";
  99        }
 100        $str .= isset($bc['line']) ? ', ' . $bc['line'] : '';
 101        $str .= ' ] ';
 102        $str .= ($html ? "<br />\n" : "\n");
 103      }
 104      return $str;
 105    }
 106  }
 107  ?>


Generated: Fri Dec 5 04:05:07 2008 Cross-referenced by PHPXref 0.7