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

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