@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
3final class PHIDLookupConduitAPIMethod extends PHIDConduitAPIMethod {
4
5 public function getAPIMethodName() {
6 return 'phid.lookup';
7 }
8
9 public function getMethodDescription() {
10 return pht('Look up objects by name.');
11 }
12
13 protected function defineParamTypes() {
14 return array(
15 'names' => 'required list<string>',
16 );
17 }
18
19 protected function defineReturnType() {
20 return 'nonempty dict<string, wild>';
21 }
22
23 protected function defineErrorTypes() {
24 return array(
25 'ERR-INVALID-PARAMETER' => pht('Must pass names.'),
26 );
27 }
28
29 protected function execute(ConduitAPIRequest $request) {
30 $names = $request->getValue('names');
31
32 if (!$names) {
33 throw new ConduitException('ERR-INVALID-PARAMETER');
34 }
35
36 $query = id(new PhabricatorObjectQuery())
37 ->setViewer($request->getUser())
38 ->withNames($names);
39 $query->execute();
40 $name_map = $query->getNamedResults();
41
42 $handles = id(new PhabricatorHandleQuery())
43 ->setViewer($request->getUser())
44 ->withPHIDs(mpull($name_map, 'getPHID'))
45 ->execute();
46
47 $result = array();
48 foreach ($name_map as $name => $object) {
49 $phid = $object->getPHID();
50 $handle = $handles[$phid];
51 $result[$name] = $this->buildHandleInformationDictionary($handle);
52 }
53
54 return $result;
55 }
56
57}