Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/storage/AlmanacService.php
Show All 15 Lines | final class AlmanacService | ||||
protected $nameIndex; | protected $nameIndex; | ||||
protected $mailKey; | protected $mailKey; | ||||
protected $viewPolicy; | protected $viewPolicy; | ||||
protected $editPolicy; | protected $editPolicy; | ||||
protected $serviceType; | protected $serviceType; | ||||
private $almanacProperties = self::ATTACHABLE; | private $almanacProperties = self::ATTACHABLE; | ||||
private $bindings = self::ATTACHABLE; | private $bindings = self::ATTACHABLE; | ||||
private $activeBindings = self::ATTACHABLE; | |||||
private $serviceImplementation = self::ATTACHABLE; | private $serviceImplementation = self::ATTACHABLE; | ||||
public static function initializeNewService($type) { | public static function initializeNewService($type) { | ||||
$type_map = AlmanacServiceType::getAllServiceTypes(); | $type_map = AlmanacServiceType::getAllServiceTypes(); | ||||
$implementation = idx($type_map, $type); | $implementation = idx($type_map, $type); | ||||
if (!$implementation) { | if (!$implementation) { | ||||
throw new Exception( | throw new Exception( | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public function getURI() { | ||||
return '/almanac/service/view/'.$this->getName().'/'; | return '/almanac/service/view/'.$this->getName().'/'; | ||||
} | } | ||||
public function getBindings() { | public function getBindings() { | ||||
return $this->assertAttached($this->bindings); | return $this->assertAttached($this->bindings); | ||||
} | } | ||||
public function getActiveBindings() { | public function getActiveBindings() { | ||||
$bindings = $this->getBindings(); | return $this->assertAttached($this->activeBindings); | ||||
} | |||||
// Filter out disabled bindings. | public function attachBindings(array $bindings) { | ||||
$active_bindings = array(); | |||||
foreach ($bindings as $key => $binding) { | foreach ($bindings as $key => $binding) { | ||||
// Filter out disabled bindings. | |||||
if ($binding->getIsDisabled()) { | if ($binding->getIsDisabled()) { | ||||
unset($bindings[$key]); | continue; | ||||
} | } | ||||
// Filter out bindings to disabled devices. | |||||
if ($binding->getDevice()->isDisabled()) { | |||||
continue; | |||||
} | } | ||||
return $bindings; | $active_bindings[$key] = $binding; | ||||
} | } | ||||
public function attachBindings(array $bindings) { | $this->attachActiveBindings($active_bindings); | ||||
$this->bindings = $bindings; | $this->bindings = $bindings; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function attachActiveBindings(array $bindings) { | |||||
$this->activeBindings = $bindings; | |||||
return $this; | |||||
} | |||||
public function getServiceImplementation() { | public function getServiceImplementation() { | ||||
return $this->assertAttached($this->serviceImplementation); | return $this->assertAttached($this->serviceImplementation); | ||||
} | } | ||||
public function attachServiceImplementation(AlmanacServiceType $type) { | public function attachServiceImplementation(AlmanacServiceType $type) { | ||||
$this->serviceImplementation = $type; | $this->serviceImplementation = $type; | ||||
return $this; | return $this; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | /* -( PhabricatorConduitResultInterface )---------------------------------- */ | ||||
} | } | ||||
public function getConduitSearchAttachments() { | public function getConduitSearchAttachments() { | ||||
return array( | return array( | ||||
id(new AlmanacPropertiesSearchEngineAttachment()) | id(new AlmanacPropertiesSearchEngineAttachment()) | ||||
->setAttachmentKey('properties'), | ->setAttachmentKey('properties'), | ||||
id(new AlmanacBindingsSearchEngineAttachment()) | id(new AlmanacBindingsSearchEngineAttachment()) | ||||
->setAttachmentKey('bindings'), | ->setAttachmentKey('bindings'), | ||||
id(new AlmanacBindingsSearchEngineAttachment()) | |||||
->setIsActive(true) | |||||
->setAttachmentKey('activeBindings'), | |||||
); | ); | ||||
} | } | ||||
} | } |