3 final class AlmanacBinding
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())
31 protected function getConfiguration() {
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'),
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() {
62 '/almanac/binding/%s/',
66 public function getService() {
67 return $this->assertAttached($this->service
);
70 public function attachService(AlmanacService
$service) {
71 $this->service
= $service;
75 public function getDevice() {
76 return $this->assertAttached($this->device
);
79 public function attachDevice(AlmanacDevice
$device) {
80 $this->device
= $device;
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;
98 /* -( AlmanacPropertyInterface )------------------------------------------- */
101 public function attachAlmanacProperties(array $properties) {
102 assert_instances_of($properties, 'AlmanacProperty');
103 $this->almanacProperties
= mpull($properties, null, 'getFieldName');
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();
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() {
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) {
165 pht('A binding inherits the policies of its service.'),
167 'To view a binding, you must also be able to view its device and '.
175 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
178 public function getExtendedPolicy($capability, PhabricatorUser
$viewer) {
179 switch ($capability) {
180 case PhabricatorPolicyCapability
::CAN_EDIT
:
181 if ($this->getService()->isClusterService()) {
184 new PhabricatorAlmanacApplication(),
185 AlmanacManageClusterServicesCapability
::CAPABILITY
,
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) {
217 /* -( PhabricatorConduitResultInterface )---------------------------------- */
220 public function getFieldSpecificationsForConduit() {
222 id(new PhabricatorConduitSearchFieldSpecification())
223 ->setKey('servicePHID')
225 ->setDescription(pht('The bound service.')),
226 id(new PhabricatorConduitSearchFieldSpecification())
227 ->setKey('devicePHID')
229 ->setDescription(pht('The device the service is bound to.')),
230 id(new PhabricatorConduitSearchFieldSpecification())
231 ->setKey('interfacePHID')
233 ->setDescription(pht('The interface the service is bound to.')),
234 id(new PhabricatorConduitSearchFieldSpecification())
237 ->setDescription(pht('Interface status.')),
241 public function getFieldValuesForConduit() {
243 'servicePHID' => $this->getServicePHID(),
244 'devicePHID' => $this->getDevicePHID(),
245 'interfacePHID' => $this->getInterfacePHID(),
246 'disabled' => (bool)$this->getIsDisabled(),
250 public function getConduitSearchAttachments() {
252 id(new AlmanacPropertiesSearchEngineAttachment())
253 ->setAttachmentKey('properties'),