Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / harbormaster / conduit / HarbormasterQueryAutotargetsConduitAPIMethod.php
bloba00324f674e9e96b3dde778c550b75b808a45d5b
1 <?php
3 final class HarbormasterQueryAutotargetsConduitAPIMethod
4 extends HarbormasterConduitAPIMethod {
6 public function getAPIMethodName() {
7 return 'harbormaster.queryautotargets';
10 public function getMethodDescription() {
11 return pht('Load or create build autotargets.');
14 protected function defineParamTypes() {
15 return array(
16 'objectPHID' => 'phid',
17 'targetKeys' => 'list<string>',
21 protected function defineReturnType() {
22 return 'map<string, phid>';
25 protected function execute(ConduitAPIRequest $request) {
26 $viewer = $request->getUser();
28 $phid = $request->getValue('objectPHID');
30 // NOTE: We use withNames() to let monograms like "D123" work, which makes
31 // this a little easier to test. Real PHIDs will still work as expected.
33 $object = id(new PhabricatorObjectQuery())
34 ->setViewer($viewer)
35 ->withNames(array($phid))
36 ->executeOne();
37 if (!$object) {
38 throw new Exception(
39 pht(
40 'No such object "%s" exists.',
41 $phid));
44 if (!($object instanceof HarbormasterBuildableInterface)) {
45 throw new Exception(
46 pht(
47 'Object "%s" does not implement interface "%s". Autotargets may '.
48 'only be queried for buildable objects.',
49 $phid,
50 'HarbormasterBuildableInterface'));
53 $autotargets = $request->getValue('targetKeys', array());
55 if ($autotargets) {
56 $targets = id(new HarbormasterTargetEngine())
57 ->setViewer($viewer)
58 ->setObject($object)
59 ->setAutoTargetKeys($autotargets)
60 ->buildTargets();
61 } else {
62 $targets = array();
65 // Reorder the results according to the request order so we can make test
66 // assertions that subsequent calls return the same results.
68 $map = mpull($targets, 'getPHID');
69 $map = array_select_keys($map, $autotargets);
71 return array(
72 'targetMap' => $map,