From d45855e33e0b98d521ea3e44a4c1f718821ec6cc Mon Sep 17 00:00:00 2001 From: Alan Huang Date: Tue, 14 Aug 2012 19:18:28 -0700 Subject: [PATCH] Expose xhpast via Conduit Summary: Create `phpast.{version,getast}` methods for calling xhpast with `--version` and with source code as input, respectively. Test Plan: Run `arc call-conduit` a bunch of times; delete xhpast; run it a bunch more times. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1534 Differential Revision: https://secure.phabricator.com/D3289 --- src/__phutil_library_map__.php | 4 ++ .../ConduitAPI_phpast_getast_Method.php | 49 +++++++++++++++++ .../ConduitAPI_phpast_version_Method.php | 55 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/applications/conduit/method/phpast/ConduitAPI_phpast_getast_Method.php create mode 100644 src/applications/conduit/method/phpast/ConduitAPI_phpast_version_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index eb746cb57b..d41d493f13 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -166,6 +166,8 @@ phutil_register_library_map(array( 'ConduitAPI_phid_info_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_info_Method.php', 'ConduitAPI_phid_lookup_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_lookup_Method.php', 'ConduitAPI_phid_query_Method' => 'applications/conduit/method/phid/ConduitAPI_phid_query_Method.php', + 'ConduitAPI_phpast_getast_Method' => 'applications/conduit/method/phpast/ConduitAPI_phpast_getast_Method.php', + 'ConduitAPI_phpast_version_Method' => 'applications/conduit/method/phpast/ConduitAPI_phpast_version_Method.php', 'ConduitAPI_phriction_Method' => 'applications/conduit/method/phriction/ConduitAPI_phriction_Method.php', 'ConduitAPI_phriction_edit_Method' => 'applications/conduit/method/phriction/ConduitAPI_phriction_edit_Method.php', 'ConduitAPI_phriction_history_Method' => 'applications/conduit/method/phriction/ConduitAPI_phriction_history_Method.php', @@ -1343,6 +1345,8 @@ phutil_register_library_map(array( 'ConduitAPI_phid_info_Method' => 'ConduitAPI_phid_Method', 'ConduitAPI_phid_lookup_Method' => 'ConduitAPI_phid_Method', 'ConduitAPI_phid_query_Method' => 'ConduitAPI_phid_Method', + 'ConduitAPI_phpast_getast_Method' => 'ConduitAPIMethod', + 'ConduitAPI_phpast_version_Method' => 'ConduitAPIMethod', 'ConduitAPI_phriction_Method' => 'ConduitAPIMethod', 'ConduitAPI_phriction_edit_Method' => 'ConduitAPI_phriction_Method', 'ConduitAPI_phriction_history_Method' => 'ConduitAPI_phriction_Method', diff --git a/src/applications/conduit/method/phpast/ConduitAPI_phpast_getast_Method.php b/src/applications/conduit/method/phpast/ConduitAPI_phpast_getast_Method.php new file mode 100644 index 0000000000..fe0dacf4d1 --- /dev/null +++ b/src/applications/conduit/method/phpast/ConduitAPI_phpast_getast_Method.php @@ -0,0 +1,49 @@ + 'required string', + ); + } + + public function defineReturnType() { + return 'nonempty dict'; + } + + public function defineErrorTypes() { + return array( + 'ERR-XHPAST-LEY' => 'xhpast got Rickrolled', + ); + } + + protected function execute(ConduitAPIRequest $request) { + return json_decode( + xhpast_get_parser_future($request->getValue('code'))->resolvex()[0]); + } + +} diff --git a/src/applications/conduit/method/phpast/ConduitAPI_phpast_version_Method.php b/src/applications/conduit/method/phpast/ConduitAPI_phpast_version_Method.php new file mode 100644 index 0000000000..3ca3a976c9 --- /dev/null +++ b/src/applications/conduit/method/phpast/ConduitAPI_phpast_version_Method.php @@ -0,0 +1,55 @@ + 'xhpast was not found on the server', + 'ERR-COMMAND-FAILED' => 'xhpast died with a nonzero exit code', + ); + } + + protected function execute(ConduitAPIRequest $request) { + $path = xhpast_get_binary_path(); + if (!Filesystem::pathExists($path)) { + throw new ConduitException('ERR-NOT-FOUND'); + } + list($err, $stdout) = exec_manual('%s --version', $path); + if ($err) { + throw new ConduitException('ERR-COMMAND-FAILED'); + } + return trim($stdout); + } + +}