Gtk2_ExceptionDump
[ class tree: Gtk2_ExceptionDump ] [ index: Gtk2_ExceptionDump ] [ all elements ]

Source for file StackModel.php

Documentation is available at StackModel.php

  1. <?php
  2.  
  3. /**
  4. *   Stack trace list model.
  5. *   Is used as model for Gtk2_ExceptionDump_Stack class
  6. *
  7. *   @author Christian Weiske <cweiske@php.net>
  8. */
  9. class Gtk2_ExceptionDump_StackModel extends GtkTreeStore
  10. {
  11.     /**
  12.     *   Creates the stack trace tree model.
  13.     *
  14.     *   @param mixed    $exception  Exception or PEAR_Error
  15.     */
  16.     public function __construct($exception = null)
  17.     {
  18.         parent::__construct(Gtk::TYPE_LONGGtk::TYPE_STRINGGTK::TYPE_STRINGGtk::TYPE_PHP_VALUE);
  19.  
  20.         if ($exception !== null{
  21.             $this->setException($exception);
  22.         }
  23.     }//public function __construct($exception = null)
  24.  
  25.  
  26.  
  27.     /**
  28.     *   Sets and displays the exception.
  29.     *
  30.     *   @param mixed    $exception  Exception or PEAR_Error
  31.     *   @param int      $nOmitLines Number of stack lines to supress
  32.     */
  33.     public function setException($exception$nOmitLines = 0)
  34.     {
  35.         $this->clear();
  36.         /* PEAR_Error->getBacktrace(): arrays with this elements:
  37.         [1]=>
  38.         array(4) {
  39.             ["file"]=>
  40.             string(61) "/data/php-gtk/two/Gtk2_ExceptionDump/examples/pear_error.phpw"
  41.             ["line"]=>
  42.             int(7)
  43.             ["function"]=>
  44.             string(1) "c"
  45.             ["args"]=>
  46.             array(3) {
  47.             [0]=>
  48.             string(3) "yes"
  49.             [1]=>
  50.             string(2) "no"
  51.             [2]=>
  52.             string(6) "cancel"
  53.             }
  54.         } */
  55.  
  56.         /* Exception->getTrace(): array with elements a la:
  57.         [0]=>
  58.         array(4) {
  59.             ["file"]=>
  60.             string(60) "/data/php-gtk/two/Gtk2_ExceptionDump/examples/exception.phpw"
  61.             ["line"]=>
  62.             int(7)
  63.             ["function"]=>
  64.             string(1) "c"
  65.             ["args"]=>
  66.             array(3) {
  67.             [0]=>
  68.             string(3) "yes"
  69.             [1]=>
  70.             string(2) "no"
  71.             [2]=>
  72.             string(6) "cancel"
  73.             }
  74.         }*/
  75.         $func $exception instanceof PEAR_Error ? 'getBacktrace' 'getTrace';
  76.  
  77.         $trace $exception->$func();
  78.         foreach ($trace as $id => $step{
  79.             if ($nOmitLines > 0{
  80.                 $nOmitLines--; continue;
  81.             }
  82.  
  83.             if (!isset($step['args']|| count($step['args']== 0{
  84.                 $function $step['function''()';
  85.             else {
  86.                 $function $step['function''(...)';
  87.             }
  88.  
  89.             if (isset($step['class'])) {
  90.                 if ($step['class'== $step['function']{
  91.                     $function 'new ' $function;
  92.                 else {
  93.                     $function $step['class'$step['type'$function;
  94.                 }
  95.             }
  96.  
  97.             if (isset($step['file'])) {
  98.                 $file basename($step['file']'#' $step['line''   ' dirname($step['file']);
  99.             else {
  100.                 $file 'unknown';
  101.             }
  102.  
  103.             $parent $this->append(nullarray(
  104.                 $id,
  105.                 $function,
  106.                 $file,
  107.                 $step
  108.             ));
  109.  
  110.             $num = 0;
  111.             if (isset($step['args'])) {
  112.                 foreach ($step['args'as $arg{
  113.                     $this->append($parentarray(
  114.                         $num++,
  115.                         gettype($arg),
  116.                         (string)$arg,
  117.                         $arg
  118.                     ));
  119.                 }
  120.             }
  121.         }
  122.  
  123.     }//public function setException($exception, $nOmitLines = 0)
  124.  
  125. }//class Gtk2_ExceptionDump_StackModel extends GtkTreeStore
  126. ?>

Documentation generated on Mon, 11 Mar 2019 14:55:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.