[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionSymbolController.php (source)

   1  <?php
   2  
   3  final class DiffusionSymbolController extends DiffusionController {
   4  
   5    private $name;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->name = $data['name'];
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $user = $request->getUser();
  14  
  15      $query = new DiffusionSymbolQuery();
  16      $query->setName($this->name);
  17  
  18      if ($request->getStr('context') !== null) {
  19        $query->setContext($request->getStr('context'));
  20      }
  21  
  22      if ($request->getStr('type')) {
  23        $query->setType($request->getStr('type'));
  24      }
  25  
  26      if ($request->getStr('lang')) {
  27        $query->setLanguage($request->getStr('lang'));
  28      }
  29  
  30      if ($request->getStr('projects')) {
  31        $phids = $request->getStr('projects');
  32        $phids = explode(',', $phids);
  33        $phids = array_filter($phids);
  34  
  35        if ($phids) {
  36          $projects = id(new PhabricatorRepositoryArcanistProject())
  37            ->loadAllWhere(
  38              'phid IN (%Ls)',
  39              $phids);
  40          $projects = mpull($projects, 'getID');
  41          if ($projects) {
  42            $query->setProjectIDs($projects);
  43          }
  44        }
  45      }
  46  
  47      $query->needPaths(true);
  48      $query->needArcanistProjects(true);
  49      $query->needRepositories(true);
  50  
  51      $symbols = $query->execute();
  52  
  53      // For PHP builtins, jump to php.net documentation.
  54      if ($request->getBool('jump') && count($symbols) == 0) {
  55        if ($request->getStr('lang', 'php') == 'php') {
  56          if ($request->getStr('type', 'function') == 'function') {
  57            $functions = get_defined_functions();
  58            if (in_array($this->name, $functions['internal'])) {
  59              return id(new AphrontRedirectResponse())
  60                ->setIsExternal(true)
  61                ->setURI('http://www.php.net/function.'.$this->name);
  62            }
  63          }
  64          if ($request->getStr('type', 'class') == 'class') {
  65            if (class_exists($this->name, false) ||
  66                interface_exists($this->name, false)) {
  67              if (id(new ReflectionClass($this->name))->isInternal()) {
  68                return id(new AphrontRedirectResponse())
  69                  ->setIsExternal(true)
  70                  ->setURI('http://www.php.net/class.'.$this->name);
  71              }
  72            }
  73          }
  74        }
  75      }
  76  
  77      $rows = array();
  78      foreach ($symbols as $symbol) {
  79        $project = $symbol->getArcanistProject();
  80        if ($project) {
  81          $project_name = $project->getName();
  82        } else {
  83          $project_name = '-';
  84        }
  85  
  86        $file = $symbol->getPath();
  87        $line = $symbol->getLineNumber();
  88  
  89        $repo = $symbol->getRepository();
  90        if ($repo) {
  91          $href = $symbol->getURI();
  92  
  93          if ($request->getBool('jump') && count($symbols) == 1) {
  94            // If this is a clickthrough from Differential, just jump them
  95            // straight to the target if we got a single hit.
  96            return id(new AphrontRedirectResponse())->setURI($href);
  97          }
  98  
  99          $location = phutil_tag(
 100            'a',
 101            array(
 102              'href' => $href,
 103            ),
 104            $file.':'.$line);
 105        } else if ($file) {
 106          $location = $file.':'.$line;
 107        } else {
 108          $location = '?';
 109        }
 110  
 111        $rows[] = array(
 112          $symbol->getSymbolType(),
 113          $symbol->getSymbolContext(),
 114          $symbol->getSymbolName(),
 115          $symbol->getSymbolLanguage(),
 116          $project_name,
 117          $location,
 118        );
 119      }
 120  
 121      $table = new AphrontTableView($rows);
 122      $table->setHeaders(
 123        array(
 124          pht('Type'),
 125          pht('Context'),
 126          pht('Name'),
 127          pht('Language'),
 128          pht('Project'),
 129          pht('File'),
 130        ));
 131      $table->setColumnClasses(
 132        array(
 133          '',
 134          '',
 135          'pri',
 136          '',
 137          '',
 138          '',
 139        ));
 140      $table->setNoDataString(
 141        pht('No matching symbol could be found in any indexed project.'));
 142  
 143      $panel = new AphrontPanelView();
 144      $panel->setHeader(pht('Similar Symbols'));
 145      $panel->appendChild($table);
 146  
 147      return $this->buildApplicationPage(
 148        array(
 149          $panel,
 150        ),
 151        array(
 152          'title' => pht('Find Symbol'),
 153        ));
 154    }
 155  
 156  }


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