@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorXHPASTViewTreeController
4 extends PhabricatorXHPASTViewPanelController {
5
6 public function shouldAllowPublic() {
7 return true;
8 }
9
10 public function handleRequest(AphrontRequest $request) {
11 $storage = $this->getStorageTree();
12 $input = $storage->getInput();
13 $err = $storage->getReturnCode();
14 $stdout = $storage->getStdout();
15 $stderr = $storage->getStderr();
16
17 try {
18 $tree = XHPASTTree::newFromDataAndResolvedExecFuture(
19 $input,
20 array($err, $stdout, $stderr));
21 } catch (XHPASTSyntaxErrorException $ex) {
22 return $this->buildXHPASTViewPanelResponse($ex->getMessage());
23 }
24
25 $tree = phutil_tag('ul', array(), $this->buildTree($tree->getRootNode()));
26 return $this->buildXHPASTViewPanelResponse($tree);
27 }
28
29 protected function buildTree($root) {
30 try {
31 $name = $root->getTypeName();
32 $title = pht('Node %d: %s', $root->getID(), $name);
33 } catch (Exception $ex) {
34 $name = '???';
35 $title = '???';
36 }
37
38 $tree = array();
39 $tree[] = phutil_tag(
40 'li',
41 array(),
42 phutil_tag(
43 'span',
44 array(
45 'title' => $title,
46 ),
47 $name));
48 foreach ($root->getChildren() as $child) {
49 $tree[] = phutil_tag('ul', array(), $this->buildTree($child));
50 }
51 return phutil_implode_html("\n", $tree);
52 }
53
54}