2011-04-06 19:17:05 -07:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhabricatorXHPASTViewTreeController
|
2011-04-06 19:17:05 -07:00
|
|
|
extends PhabricatorXHPASTViewPanelController {
|
|
|
|
|
2015-07-22 13:26:13 -07:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-04 09:33:13 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2011-04-06 19:17:05 -07:00
|
|
|
$storage = $this->getStorageTree();
|
|
|
|
$input = $storage->getInput();
|
2015-11-08 21:54:47 +11:00
|
|
|
$err = $storage->getReturnCode();
|
2011-04-06 19:17:05 -07:00
|
|
|
$stdout = $storage->getStdout();
|
2015-11-08 21:54:47 +11:00
|
|
|
$stderr = $storage->getStderr();
|
2011-04-06 19:17:05 -07:00
|
|
|
|
2015-11-08 21:54:47 +11:00
|
|
|
try {
|
|
|
|
$tree = XHPASTTree::newFromDataAndResolvedExecFuture(
|
|
|
|
$input,
|
|
|
|
array($err, $stdout, $stderr));
|
|
|
|
} catch (XHPASTSyntaxErrorException $ex) {
|
|
|
|
return $this->buildXHPASTViewPanelResponse($ex->getMessage());
|
|
|
|
}
|
2011-04-06 19:17:05 -07:00
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
$tree = phutil_tag('ul', array(), $this->buildTree($tree->getRootNode()));
|
2011-04-06 19:17:05 -07:00
|
|
|
return $this->buildXHPASTViewPanelResponse($tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildTree($root) {
|
|
|
|
try {
|
|
|
|
$name = $root->getTypeName();
|
2015-12-23 08:39:23 +11:00
|
|
|
$title = pht('Node %d: %s', $root->getID(), $name);
|
2011-04-06 19:17:05 -07:00
|
|
|
} catch (Exception $ex) {
|
|
|
|
$name = '???';
|
|
|
|
$title = '???';
|
|
|
|
}
|
|
|
|
|
|
|
|
$tree = array();
|
2013-02-13 14:50:15 -08:00
|
|
|
$tree[] = phutil_tag(
|
|
|
|
'li',
|
|
|
|
array(),
|
|
|
|
phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
),
|
|
|
|
$name));
|
2011-04-06 19:17:05 -07:00
|
|
|
foreach ($root->getChildren() as $child) {
|
2013-02-13 14:50:15 -08:00
|
|
|
$tree[] = phutil_tag('ul', array(), $this->buildTree($child));
|
2011-04-06 19:17:05 -07:00
|
|
|
}
|
2013-02-13 14:50:15 -08:00
|
|
|
return phutil_implode_html("\n", $tree);
|
2011-04-06 19:17:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|