Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / storage / AlmanacBinding.php
blob011a08515135eabcaf3f85e5dc18286233a67d22
1 <?php
3 final class AlmanacBinding
4 extends AlmanacDAO
5 implements
6 PhabricatorPolicyInterface,
7 PhabricatorApplicationTransactionInterface,
8 AlmanacPropertyInterface,
9 PhabricatorDestructibleInterface,
10 PhabricatorExtendedPolicyInterface,
11 PhabricatorConduitResultInterface {
13 protected $servicePHID;
14 protected $devicePHID;
15 protected $interfacePHID;
16 protected $isDisabled;
18 private $service = self::ATTACHABLE;
19 private $device = self::ATTACHABLE;
20 private $interface = self::ATTACHABLE;
21 private $almanacProperties = self::ATTACHABLE;
23 public static function initializeNewBinding(AlmanacService $service) {
24 return id(new AlmanacBinding())
25 ->setServicePHID($service->getPHID())
26 ->attachService($service)
27 ->attachAlmanacProperties(array())
28 ->setIsDisabled(0);
31 protected function getConfiguration() {
32 return array(
33 self::CONFIG_AUX_PHID => true,
34 self::CONFIG_COLUMN_SCHEMA => array(
35 'isDisabled' => 'bool',
37 self::CONFIG_KEY_SCHEMA => array(
38 'key_service' => array(
39 'columns' => array('servicePHID', 'interfacePHID'),
40 'unique' => true,
42 'key_device' => array(
43 'columns' => array('devicePHID'),
45 'key_interface' => array(
46 'columns' => array('interfacePHID'),
49 ) + parent::getConfiguration();
52 public function getPHIDType() {
53 return AlmanacBindingPHIDType::TYPECONST;
56 public function getName() {
57 return pht('Binding %s', $this->getID());
60 public function getURI() {
61 return urisprintf(
62 '/almanac/binding/%s/',
63 $this->getID());
66 public function getService() {
67 return $this->assertAttached($this->service);
70 public function attachService(AlmanacService $service) {
71 $this->service = $service;
72 return $this;
75 public function getDevice() {
76 return $this->assertAttached($this->device);
79 public function attachDevice(AlmanacDevice $device) {
80 $this->device = $device;
81 return $this;
84 public function hasInterface() {
85 return ($this->interface !== self::ATTACHABLE);
88 public function getInterface() {
89 return $this->assertAttached($this->interface);
92 public function attachInterface(AlmanacInterface $interface) {
93 $this->interface = $interface;
94 return $this;
98 /* -( AlmanacPropertyInterface )------------------------------------------- */
101 public function attachAlmanacProperties(array $properties) {
102 assert_instances_of($properties, 'AlmanacProperty');
103 $this->almanacProperties = mpull($properties, null, 'getFieldName');
104 return $this;
107 public function getAlmanacProperties() {
108 return $this->assertAttached($this->almanacProperties);
111 public function hasAlmanacProperty($key) {
112 $this->assertAttached($this->almanacProperties);
113 return isset($this->almanacProperties[$key]);
116 public function getAlmanacProperty($key) {
117 return $this->assertAttachedKey($this->almanacProperties, $key);
120 public function getAlmanacPropertyValue($key, $default = null) {
121 if ($this->hasAlmanacProperty($key)) {
122 return $this->getAlmanacProperty($key)->getFieldValue();
123 } else {
124 return $default;
128 public function getAlmanacPropertyFieldSpecifications() {
129 return $this->getService()->getBindingFieldSpecifications($this);
132 public function newAlmanacPropertyEditEngine() {
133 return new AlmanacBindingPropertyEditEngine();
136 public function getAlmanacPropertySetTransactionType() {
137 return AlmanacBindingSetPropertyTransaction::TRANSACTIONTYPE;
140 public function getAlmanacPropertyDeleteTransactionType() {
141 return AlmanacBindingDeletePropertyTransaction::TRANSACTIONTYPE;
145 /* -( PhabricatorPolicyInterface )----------------------------------------- */
148 public function getCapabilities() {
149 return array(
150 PhabricatorPolicyCapability::CAN_VIEW,
151 PhabricatorPolicyCapability::CAN_EDIT,
155 public function getPolicy($capability) {
156 return $this->getService()->getPolicy($capability);
159 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
160 return $this->getService()->hasAutomaticCapability($capability, $viewer);
163 public function describeAutomaticCapability($capability) {
164 $notes = array(
165 pht('A binding inherits the policies of its service.'),
166 pht(
167 'To view a binding, you must also be able to view its device and '.
168 'interface.'),
171 return $notes;
175 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
178 public function getExtendedPolicy($capability, PhabricatorUser $viewer) {
179 switch ($capability) {
180 case PhabricatorPolicyCapability::CAN_EDIT:
181 if ($this->getService()->isClusterService()) {
182 return array(
183 array(
184 new PhabricatorAlmanacApplication(),
185 AlmanacManageClusterServicesCapability::CAPABILITY,
189 break;
192 return array();
195 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
198 public function getApplicationTransactionEditor() {
199 return new AlmanacBindingEditor();
202 public function getApplicationTransactionTemplate() {
203 return new AlmanacBindingTransaction();
207 /* -( PhabricatorDestructibleInterface )----------------------------------- */
210 public function destroyObjectPermanently(
211 PhabricatorDestructionEngine $engine) {
213 $this->delete();
217 /* -( PhabricatorConduitResultInterface )---------------------------------- */
220 public function getFieldSpecificationsForConduit() {
221 return array(
222 id(new PhabricatorConduitSearchFieldSpecification())
223 ->setKey('servicePHID')
224 ->setType('phid')
225 ->setDescription(pht('The bound service.')),
226 id(new PhabricatorConduitSearchFieldSpecification())
227 ->setKey('devicePHID')
228 ->setType('phid')
229 ->setDescription(pht('The device the service is bound to.')),
230 id(new PhabricatorConduitSearchFieldSpecification())
231 ->setKey('interfacePHID')
232 ->setType('phid')
233 ->setDescription(pht('The interface the service is bound to.')),
234 id(new PhabricatorConduitSearchFieldSpecification())
235 ->setKey('disabled')
236 ->setType('bool')
237 ->setDescription(pht('Interface status.')),
241 public function getFieldValuesForConduit() {
242 return array(
243 'servicePHID' => $this->getServicePHID(),
244 'devicePHID' => $this->getDevicePHID(),
245 'interfacePHID' => $this->getInterfacePHID(),
246 'disabled' => (bool)$this->getIsDisabled(),
250 public function getConduitSearchAttachments() {
251 return array(
252 id(new AlmanacPropertiesSearchEngineAttachment())
253 ->setAttachmentKey('properties'),