@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
at upstream/main 86 lines 2.4 kB view raw
1<?php 2 3final class PhabricatorXHPASTViewRunController 4 extends PhabricatorXHPASTViewController { 5 6 protected function buildApplicationCrumbs() { 7 return parent::buildApplicationCrumbs() 8 ->addAction( 9 id(new PHUIListItemView()) 10 ->setName(pht('Use PHPAST')) 11 ->setHref('/phpast/') 12 ->setIcon('fa-random')); 13 } 14 15 public function handleRequest(AphrontRequest $request) { 16 $viewer = $this->getViewer(); 17 18 if ($request->isFormPost()) { 19 $source = $request->getStr('source'); 20 21 $future = PhutilXHPASTBinary::getParserFuture($source); 22 $resolved = $future->resolve(); 23 24 // This is just to let it throw exceptions if stuff is broken. 25 try { 26 XHPASTTree::newFromDataAndResolvedExecFuture($source, $resolved); 27 } catch (XHPASTSyntaxErrorException $ex) { 28 // This is possibly expected. 29 } 30 31 list($err, $stdout, $stderr) = $resolved; 32 33 $storage_tree = id(new PhabricatorXHPASTParseTree()) 34 ->setInput($source) 35 ->setReturnCode($err) 36 ->setStdout($stdout) 37 ->setStderr($stderr) 38 ->setAuthorPHID($viewer->getPHID()) 39 ->save(); 40 41 return id(new AphrontRedirectResponse()) 42 ->setURI('/xhpast/view/'.$storage_tree->getID().'/'); 43 } 44 45 $form = id(new AphrontFormView()) 46 ->setViewer($viewer) 47 ->appendChild( 48 id(new AphrontFormTextAreaControl()) 49 ->setLabel(pht('Source')) 50 ->setName('source') 51 ->setValue("<?php\n\n") 52 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)) 53 ->appendChild( 54 id(new AphrontFormSubmitControl()) 55 ->setValue(pht('Parse'))); 56 57 $form_box = id(new PHUIObjectBoxView()) 58 ->setHeaderText(pht('Generate XHP AST')) 59 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 60 ->setForm($form); 61 62 $title = pht('XHPAST View'); 63 $header = id(new PHUIHeaderView()) 64 ->setHeader($title) 65 ->setHeaderIcon('fa-ambulance'); 66 67 $view = id(new PHUITwoColumnView()) 68 ->setHeader($header) 69 ->setFooter(array( 70 $form_box, 71 )); 72 73 return $this->newPage() 74 ->setTitle($title) 75 ->setCrumbs( 76 id(new PHUICrumbsView()) 77 ->addAction( 78 id(new PHUIListItemView()) 79 ->setName(pht('Use PHPAST')) 80 ->setHref('/phpast/') 81 ->setIcon('fa-random'))) 82 ->appendChild($view); 83 84 } 85 86}