[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AlmanacQueryServicesConduitAPIMethod 4 extends AlmanacConduitAPIMethod { 5 6 public function getAPIMethodName() { 7 return 'almanac.queryservices'; 8 } 9 10 public function getMethodDescription() { 11 return pht('Query Almanac services.'); 12 } 13 14 public function defineParamTypes() { 15 return array( 16 'ids' => 'optional list<id>', 17 'phids' => 'optional list<phid>', 18 'names' => 'optional list<phid>', 19 ) + self::getPagerParamTypes(); 20 } 21 22 public function defineReturnType() { 23 return 'list<wild>'; 24 } 25 26 public function defineErrorTypes() { 27 return array(); 28 } 29 30 protected function execute(ConduitAPIRequest $request) { 31 $viewer = $request->getUser(); 32 33 $query = id(new AlmanacServiceQuery()) 34 ->setViewer($viewer); 35 36 $ids = $request->getValue('ids'); 37 if ($ids !== null) { 38 $query->withIDs($ids); 39 } 40 41 $phids = $request->getValue('phids'); 42 if ($phids !== null) { 43 $query->withPHIDs($phids); 44 } 45 46 $names = $request->getValue('names'); 47 if ($names !== null) { 48 $query->withNames($names); 49 } 50 51 $pager = $this->newPager($request); 52 53 $services = $query->executeWithCursorPager($pager); 54 55 if ($services) { 56 $bindings = id(new AlmanacBindingQuery()) 57 ->setViewer($viewer) 58 ->withServicePHIDs(mpull($services, 'getPHID')) 59 ->execute(); 60 $bindings = mgroup($bindings, 'getServicePHID'); 61 } else { 62 $bindings = array(); 63 } 64 65 $data = array(); 66 foreach ($services as $service) { 67 $phid = $service->getPHID(); 68 69 $properties = $service->getAlmanacProperties(); 70 $properties = mpull($properties, 'getFieldValue', 'getFieldName'); 71 72 $service_bindings = idx($bindings, $phid, array()); 73 $service_bindings = array_values($service_bindings); 74 foreach ($service_bindings as $key => $service_binding) { 75 $service_bindings[$key] = $this->getBindingDictionary($service_binding); 76 } 77 78 $data[] = $this->getServiceDictionary($service) + array( 79 'bindings' => $service_bindings, 80 ); 81 } 82 83 $results = array( 84 'data' => $data, 85 ); 86 87 return $this->addPagerResults($results, $pager); 88 } 89 90 private function getServiceDictionary(AlmanacService $service) { 91 return array( 92 'id' => (int)$service->getID(), 93 'phid' => $service->getPHID(), 94 'name' => $service->getName(), 95 'uri' => PhabricatorEnv::getProductionURI($service->getURI()), 96 'properties' => $this->getPropertiesDictionary($service), 97 ); 98 } 99 100 private function getBindingDictionary(AlmanacBinding $binding) { 101 return array( 102 'id' => (int)$binding->getID(), 103 'phid' => $binding->getPHID(), 104 'properties' => $this->getPropertiesDictionary($binding), 105 'interface' => $this->getInterfaceDictionary($binding->getInterface()), 106 ); 107 } 108 109 private function getPropertiesDictionary(AlmanacPropertyInterface $obj) { 110 $properties = $obj->getAlmanacProperties(); 111 return (object)mpull($properties, 'getFieldValue', 'getFieldName'); 112 } 113 114 private function getInterfaceDictionary(AlmanacInterface $interface) { 115 return array( 116 'id' => (int)$interface->getID(), 117 'phid' => $interface->getPHID(), 118 'address' => $interface->getAddress(), 119 'port' => (int)$interface->getPort(), 120 'device' => $this->getDeviceDictionary($interface->getDevice()), 121 'network' => $this->getNetworkDictionary($interface->getNetwork()), 122 ); 123 } 124 125 private function getDeviceDictionary(AlmanacDevice $device) { 126 return array( 127 'id' => (int)$device->getID(), 128 'phid' => $device->getPHID(), 129 'name' => $device->getName(), 130 'properties' => $this->getPropertiesDictionary($device), 131 ); 132 } 133 134 private function getNetworkDictionary(AlmanacNetwork $network) { 135 return array( 136 'id' => (int)$network->getID(), 137 'phid' => $network->getPHID(), 138 'name' => $network->getName(), 139 ); 140 } 141 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |