[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/widget/ -> AphrontStackTraceView.php (source)

   1  <?php
   2  
   3  final class AphrontStackTraceView extends AphrontView {
   4  
   5    private $trace;
   6  
   7    public function setTrace($trace) {
   8      $this->trace = $trace;
   9      return $this;
  10    }
  11  
  12    public function render() {
  13      $user = $this->getUser();
  14      $trace = $this->trace;
  15  
  16      $libraries = PhutilBootloader::getInstance()->getAllLibraries();
  17  
  18      // TODO: Make this configurable?
  19      $path = 'https://secure.phabricator.com/diffusion/%s/browse/master/src/';
  20  
  21      $callsigns = array(
  22        'arcanist' => 'ARC',
  23        'phutil' => 'PHU',
  24        'phabricator' => 'P',
  25      );
  26  
  27      $rows = array();
  28      $depth = count($trace);
  29      foreach ($trace as $part) {
  30        $lib = null;
  31        $file = idx($part, 'file');
  32        $relative = $file;
  33        foreach ($libraries as $library) {
  34          $root = phutil_get_library_root($library);
  35          if (Filesystem::isDescendant($file, $root)) {
  36            $lib = $library;
  37            $relative = Filesystem::readablePath($file, $root);
  38            break;
  39          }
  40        }
  41  
  42        $where = '';
  43        if (isset($part['class'])) {
  44          $where .= $part['class'].'::';
  45        }
  46        if (isset($part['function'])) {
  47          $where .= $part['function'].'()';
  48        }
  49  
  50        if ($file) {
  51          if (isset($callsigns[$lib])) {
  52            $attrs = array('title' => $file);
  53            try {
  54              $attrs['href'] = $user->loadEditorLink(
  55                '/src/'.$relative,
  56                $part['line'],
  57                $callsigns[$lib]);
  58            } catch (Exception $ex) {
  59              // The database can be inaccessible.
  60            }
  61            if (empty($attrs['href'])) {
  62              $attrs['href'] = sprintf($path, $callsigns[$lib]).
  63                str_replace(DIRECTORY_SEPARATOR, '/', $relative).
  64                '$'.$part['line'];
  65              $attrs['target'] = '_blank';
  66            }
  67            $file_name = phutil_tag(
  68              'a',
  69              $attrs,
  70              $relative);
  71          } else {
  72            $file_name = phutil_tag(
  73              'span',
  74              array(
  75                'title' => $file,
  76              ),
  77              $relative);
  78          }
  79          $file_name = hsprintf('%s : %d', $file_name, $part['line']);
  80        } else {
  81          $file_name = phutil_tag('em', array(), '(Internal)');
  82        }
  83  
  84  
  85        $rows[] = array(
  86          $depth--,
  87          $lib,
  88          $file_name,
  89          $where,
  90        );
  91      }
  92      $table = new AphrontTableView($rows);
  93      $table->setHeaders(
  94        array(
  95          'Depth',
  96          'Library',
  97          'File',
  98          'Where',
  99        ));
 100      $table->setColumnClasses(
 101        array(
 102          'n',
 103          '',
 104          '',
 105          'wide',
 106        ));
 107  
 108      return phutil_tag(
 109        'div',
 110        array('class' => 'exception-trace'),
 111        array(
 112          phutil_tag(
 113            'div',
 114            array('class' => 'exception-trace-header'),
 115            pht('Stack Trace')),
 116          $table->render(),
 117        ));
 118    }
 119  
 120  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1