[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/pake/ -> pakeException.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the pake package.
   5   * (c) 2004, 2005 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * 
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * pakeException is the base class for all pake related exceptions and
  13   * provides an additional method for printing up a detailed view of an
  14   * exception.
  15   *
  16   * @package    pake
  17   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  18   * @version    SVN: $Id: pakeException.class.php 2795 2006-11-23 19:51:21Z fabien $
  19   */
  20  class pakeException extends Exception
  21  {
  22    public static function strlen($string)
  23    {
  24        return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
  25    }
  26  
  27    function render($e)
  28    {
  29      $title = '  ['.get_class($e).']  ';
  30      $len = self::strlen($title);
  31      $lines = array();
  32      foreach (explode("\n", $e->getMessage()) as $line)
  33      {
  34        $lines[] = '  '.$line.'  ';
  35        $len = max(self::strlen($line) + 4, $len);
  36      }
  37      $messages = array(
  38        str_repeat(' ', $len),
  39        $title.str_repeat(' ', $len - self::strlen($title)),
  40      );
  41  
  42      foreach ($lines as $line)
  43      {
  44        $messages[] = $line.str_repeat(' ', $len - self::strlen($line));
  45      }
  46  
  47      $messages[] = str_repeat(' ', $len);
  48  
  49      fwrite(STDERR, "\n");
  50      foreach ($messages as $message)
  51      {
  52        fwrite(STDERR, pakeColor::colorize($message, 'ERROR', STDERR)."\n");
  53      }
  54      fwrite(STDERR, "\n");
  55  
  56      $pake = pakeApp::get_instance();
  57  
  58      if ($pake->get_trace())
  59      {
  60        fwrite(STDERR, "exception trace:\n");
  61  
  62        $trace = $this->trace($e);
  63        for ($i = 0, $count = count($trace); $i < $count; $i++)
  64        {
  65          $class = (isset($trace[$i]['class']) ? $trace[$i]['class'] : '');
  66          $type = (isset($trace[$i]['type']) ? $trace[$i]['type'] : '');
  67          $function = $trace[$i]['function'];
  68          $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
  69          $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
  70  
  71          fwrite(STDERR, sprintf(" %s%s%s at %s:%s\n", $class, $type, $function, pakeColor::colorize($file, 'INFO', STDERR), pakeColor::colorize($line, 'INFO', STDERR)));
  72        }
  73      }
  74  
  75      fwrite(STDERR, "\n");
  76    }
  77  
  78    function trace($exception)
  79    {
  80      // exception related properties
  81      $trace = $exception->getTrace();
  82      array_unshift($trace, array(
  83        'function' => '',
  84        'file'     => ($exception->getFile() != null) ? $exception->getFile() : 'n/a',
  85        'line'     => ($exception->getLine() != null) ? $exception->getLine() : 'n/a',
  86        'args'     => array(),
  87      ));
  88  
  89      return $trace;
  90    }
  91  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7