Public paste
exception-writer
By: fruffl | Date: Jan 15 2010 13:50 | Format: PHP | Expires: never | Size: 3.33 KB | Hits: 920

  1. <?php
  2.         ABSTRACT CLASS ILLI_Exception EXTENDS EXCEPTION
  3.         {
  4.  
  5.                 /**
  6.                  * display error-messages
  7.                  *
  8.                  * @final
  9.                  * @static
  10.                  * @param array $e                      the exception
  11.                  * @param bool $exit                    die() on exception-end
  12.                  */
  13.                 final public static function w($e, $exit = true)
  14.                 {
  15.  
  16.                         $fire_b = '<div style="background: #eee; color: #333; font-size: 11px;
  17.                                         font-family: monospace; padding: 20px;
  18.                                         border-bottom: 1px solid maroon;">%1$s</div>';
  19.                         $fire_i = '<div style="color: #333; font-size: 11px; font-family: monospace;
  20.                                         padding: 10px; border: 1px solid #ddd; padding: 20px;
  21.                                         background: #f1f1f1; border-bottom: 1px solid maroon;">%1$s</div>';
  22.                         $fire_h = '<h1 style="color: maroon; font-size: 28px;
  23.                                         font-weight: normal; font-family: Georgia,serif;">%1$s</h1>';
  24.                         $fire_l = '<div><strong>%1$s:</strong></div><div style="padding-left: 50px;
  25.                                         padding-bottom: 5px;">%2$s<br /></div>';
  26.                         $fire_c = '<pre style="border: 1px solid #ddd;
  27.                                                 padding: 20px; background: #f1f1f1;">%1$s</pre>';
  28.  
  29.                         foreach(($r = $e->getTrace()) as $b)
  30.                         {
  31.  
  32.                                 $_t = '';
  33.                                 foreach($b as $k => $v)
  34.                                         if($k != 'args')
  35.                                         {
  36.                                                 $_t .= sprintf($fire_l, $k, $v);
  37.                                         }
  38.                                         else
  39.                                         {
  40.                                                 $_a = '';
  41.                                                 foreach($b['args'] as $s => $a)
  42.                                                         if(is_array($a))
  43.                                                                 foreach($a as $c => $b)
  44.                                                                 {
  45.                                                                         ob_start();
  46.                                                                         echo '<pre>';
  47.                                                                         var_dump($b);
  48.                                                                         echo '</pre>';
  49.                                                                         $b = ob_get_clean();
  50.                                                                         $_a .= sprintf($fire_l, $c, $b);
  51.                                                                 }
  52.                                                 $_t .= sprintf($fire_l, 'args', $_a);
  53.                                         }
  54.  
  55.                                 $t .= sprintf($fire_i, $_t);
  56.                         }
  57.  
  58.  
  59.  
  60.                         if(!@preg_match('#config.php|settings.php#', ($f = $r[0]['file'])) && @file_exists($f))
  61.                         {
  62.                                 $p = @file($f);
  63.                                 $c = "";
  64.                                 $l = $r[0]['line'];
  65.                                 if(isset($p[$l-4])) $c .= ($l-3) .": ".
  66.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l-4]));
  67.                                 if(isset($p[$l-3])) $c .= ($l-2) .": ".
  68.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l-3]));
  69.                                 if(isset($p[$l-2])) $c .= ($l-1) .": ".
  70.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l-2]));
  71.                                 $c .= ($l)   .": ".
  72.                                         '<span style="color: maroon; font-weight: normal;">'.
  73.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l-1]))."</span>";
  74.                                 if(isset($p[$l]))   $c .= ($l+1) .": ".
  75.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l]));
  76.                                 if(isset($p[$l+1])) $c .= ($l+2) .": ".
  77.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l+1]));
  78.                                 if(isset($p[$l+2])) $c .= ($l+3) .": ".
  79.                                         str_replace(" ", "&nbsp;", htmlspecialchars($p[$l+2]));
  80.                                 $code = sprintf($fire_c, $c);
  81.                                 unset($p); unset($l); unset($c);
  82.                         }
  83.                         unset($r);
  84.  
  85.  
  86.                         $r = sprintf($fire_b,
  87.                                         sprintf($fire_h, get_class($e)).
  88.                                         sprintf($fire_l, 'code', nl2br($e->getCode())).
  89.                                         sprintf($fire_l, 'file', nl2br($e->getFile())).
  90.                                         sprintf($fire_l, 'line', nl2br($e->getLine())).
  91.                                         sprintf($fire_l, 'exception', get_class($e)).
  92.                                         sprintf($fire_l, 'message', $e->getMessage()).
  93.                                         sprintf($fire_l, 'code', $code).
  94.                                         sprintf($fire_l, 'string', nl2br($e->getTraceAsString())).
  95.                                         sprintf($fire_l, 'trace', $t)
  96.                                         );
  97.  
  98.  
  99.                         $p = array(rtrim(str_replace(array("/","\"), DIRECTORY_SEPARATOR,
  100.                                 dirname(dirname(__FILE__))), '/\').DIRECTORY_SEPARATOR);
  101.                         $l = array(NULL);
  102.  
  103.                         echo str_replace($p, $l, $r);
  104.  
  105.                         if($exit)
  106.                                 die();
  107.  
  108.                 }
  109.  
  110.         }