@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
3abstract class PhorgePHPASTViewPanelController
4 extends PhabricatorXHPASTViewController {
5
6 private $id;
7 private $storageTree;
8
9 public function shouldAllowPublic() {
10 return true;
11 }
12
13 public function willProcessRequest(array $data) {
14 // Load the parser now to ensure the autoloader for PHP-Parser is available.
15 PhutilPHPParserLibrary::getParser();
16
17 $this->id = $data['id'];
18 $this->storageTree = id(new PhorgePHPASTParseTree())
19 ->load($this->id);
20
21 if (!$this->storageTree) {
22 throw new Exception(pht('No such AST!'));
23 }
24 }
25
26 protected function getStorageTree() {
27 return $this->storageTree;
28 }
29
30 protected function buildPHPASTViewPanelResponse($content) {
31 $content = hsprintf(
32 '<!DOCTYPE html>'.
33 '<html>'.
34 '<head>'.
35 '<style>
36body {
37 white-space: pre;
38 font: 10px "Monaco";
39 cursor: pointer;
40}
41
42.token {
43 padding: 2px 4px;
44 margin: 2px 2px;
45 border: 1px solid #bbbbbb;
46 line-height: 24px;
47}
48
49ul {
50 margin: 0 0 0 1em;
51 padding: 0;
52 list-style: none;
53 line-height: 1em;
54}
55
56li {
57 margin: 0;
58 padding: 0;
59}
60
61li span {
62 background: #dddddd;
63 padding: 3px 6px;
64}
65
66 </style>'.
67 '</head>'.
68 '<body>%s</body>'.
69 '</html>',
70 $content);
71
72 return id(new AphrontWebpageResponse())
73 ->setFrameable(true)
74 ->setContent($content);
75 }
76
77}