1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-01 09:28:22 +01:00
phorge-phorge/src/applications/phpast/controller/PhabricatorXHPASTViewTreeController.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2011-04-06 19:17:05 -07:00
<?php
final class PhabricatorXHPASTViewTreeController
2011-04-06 19:17:05 -07:00
extends PhabricatorXHPASTViewPanelController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
2011-04-06 19:17:05 -07:00
$storage = $this->getStorageTree();
$input = $storage->getInput();
$err = $storage->getReturnCode();
2011-04-06 19:17:05 -07:00
$stdout = $storage->getStdout();
$stderr = $storage->getStderr();
2011-04-06 19:17:05 -07: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();
$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
}
}