3 final class AlmanacInterface
6 PhabricatorPolicyInterface
,
7 PhabricatorDestructibleInterface
,
8 PhabricatorExtendedPolicyInterface
,
9 PhabricatorApplicationTransactionInterface
,
10 PhabricatorConduitResultInterface
{
12 protected $devicePHID;
13 protected $networkPHID;
17 private $device = self
::ATTACHABLE
;
18 private $network = self
::ATTACHABLE
;
20 public static function initializeNewInterface() {
21 return id(new AlmanacInterface());
24 protected function getConfiguration() {
26 self
::CONFIG_AUX_PHID
=> true,
27 self
::CONFIG_COLUMN_SCHEMA
=> array(
28 'address' => 'text64',
31 self
::CONFIG_KEY_SCHEMA
=> array(
32 'key_location' => array(
33 'columns' => array('networkPHID', 'address', 'port'),
35 'key_device' => array(
36 'columns' => array('devicePHID'),
38 'key_unique' => array(
39 'columns' => array('devicePHID', 'networkPHID', 'address', 'port'),
43 ) + parent
::getConfiguration();
46 public function generatePHID() {
47 return PhabricatorPHID
::generateNewPHID(
48 AlmanacInterfacePHIDType
::TYPECONST
);
51 public function getDevice() {
52 return $this->assertAttached($this->device
);
55 public function attachDevice(AlmanacDevice
$device) {
56 $this->device
= $device;
60 public function getNetwork() {
61 return $this->assertAttached($this->network
);
64 public function attachNetwork(AlmanacNetwork
$network) {
65 $this->network
= $network;
69 public function toAddress() {
70 return AlmanacAddress
::newFromParts(
71 $this->getNetworkPHID(),
76 public function getAddressHash() {
77 return $this->toAddress()->toHash();
80 public function renderDisplayAddress() {
81 return $this->getAddress().':'.$this->getPort();
84 public function loadIsInUse() {
85 $binding = id(new AlmanacBindingQuery())
86 ->setViewer(PhabricatorUser
::getOmnipotentUser())
87 ->withInterfacePHIDs(array($this->getPHID()))
91 return (bool)$binding;
95 /* -( PhabricatorPolicyInterface )----------------------------------------- */
98 public function getCapabilities() {
100 PhabricatorPolicyCapability
::CAN_VIEW
,
101 PhabricatorPolicyCapability
::CAN_EDIT
,
105 public function getPolicy($capability) {
106 return $this->getDevice()->getPolicy($capability);
109 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
110 return $this->getDevice()->hasAutomaticCapability($capability, $viewer);
113 public function describeAutomaticCapability($capability) {
115 pht('An interface inherits the policies of the device it belongs to.'),
117 'You must be able to view the network an interface resides on to '.
118 'view the interface.'),
125 /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */
128 public function getExtendedPolicy($capability, PhabricatorUser
$viewer) {
129 switch ($capability) {
130 case PhabricatorPolicyCapability
::CAN_EDIT
:
131 if ($this->getDevice()->isClusterDevice()) {
134 new PhabricatorAlmanacApplication(),
135 AlmanacManageClusterServicesCapability
::CAPABILITY
,
146 /* -( PhabricatorDestructibleInterface )----------------------------------- */
149 public function destroyObjectPermanently(
150 PhabricatorDestructionEngine
$engine) {
152 $bindings = id(new AlmanacBindingQuery())
153 ->setViewer($engine->getViewer())
154 ->withInterfacePHIDs(array($this->getPHID()))
156 foreach ($bindings as $binding) {
157 $engine->destroyObject($binding);
164 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
167 public function getApplicationTransactionEditor() {
168 return new AlmanacInterfaceEditor();
171 public function getApplicationTransactionTemplate() {
172 return new AlmanacInterfaceTransaction();
176 /* -( PhabricatorConduitResultInterface )---------------------------------- */
179 public function getFieldSpecificationsForConduit() {
181 id(new PhabricatorConduitSearchFieldSpecification())
182 ->setKey('devicePHID')
184 ->setDescription(pht('The device the interface is on.')),
185 id(new PhabricatorConduitSearchFieldSpecification())
186 ->setKey('networkPHID')
188 ->setDescription(pht('The network the interface is part of.')),
189 id(new PhabricatorConduitSearchFieldSpecification())
192 ->setDescription(pht('The address of the interface.')),
193 id(new PhabricatorConduitSearchFieldSpecification())
196 ->setDescription(pht('The port number of the interface.')),
200 public function getFieldValuesForConduit() {
202 'devicePHID' => $this->getDevicePHID(),
203 'networkPHID' => $this->getNetworkPHID(),
204 'address' => (string)$this->getAddress(),
205 'port' => (int)$this->getPort(),
209 public function getConduitSearchAttachments() {