Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/storage/PhabricatorRepositoryURI.php
| <?php | <?php | ||||
| final class PhabricatorRepositoryURI | final class PhabricatorRepositoryURI | ||||
| extends PhabricatorRepositoryDAO { | extends PhabricatorRepositoryDAO | ||||
| implements | |||||
| PhabricatorApplicationTransactionInterface, | |||||
| PhabricatorPolicyInterface, | |||||
| PhabricatorExtendedPolicyInterface { | |||||
| protected $repositoryPHID; | protected $repositoryPHID; | ||||
| protected $uri; | protected $uri; | ||||
| protected $builtinProtocol; | protected $builtinProtocol; | ||||
| protected $builtinIdentifier; | protected $builtinIdentifier; | ||||
| protected $credentialPHID; | protected $credentialPHID; | ||||
| protected $ioType; | protected $ioType; | ||||
| protected $displayType; | protected $displayType; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public static function initializeNewURI(PhabricatorRepository $repository) { | ||||
| return id(new self()) | return id(new self()) | ||||
| ->attachRepository($repository) | ->attachRepository($repository) | ||||
| ->setRepositoryPHID($repository->getPHID()) | ->setRepositoryPHID($repository->getPHID()) | ||||
| ->setIoType(self::IO_DEFAULT) | ->setIoType(self::IO_DEFAULT) | ||||
| ->setDisplayType(self::DISPLAY_DEFAULT) | ->setDisplayType(self::DISPLAY_DEFAULT) | ||||
| ->setIsDisabled(0); | ->setIsDisabled(0); | ||||
| } | } | ||||
| public function generatePHID() { | |||||
| return PhabricatorPHID::generateNewPHID( | |||||
| PhabricatorRepositoryURIPHIDType::TYPECONST); | |||||
| } | |||||
| public function attachRepository(PhabricatorRepository $repository) { | public function attachRepository(PhabricatorRepository $repository) { | ||||
| $this->repository = $repository; | $this->repository = $repository; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getRepository() { | public function getRepository() { | ||||
| return $this->assertAttached($this->repository); | return $this->assertAttached($this->repository); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | if ($this->isBuiltin()) { | ||||
| if ($any_observe) { | if ($any_observe) { | ||||
| return self::IO_READ; | return self::IO_READ; | ||||
| } else { | } else { | ||||
| return self::IO_READWRITE; | return self::IO_READWRITE; | ||||
| } | } | ||||
| } | } | ||||
| return self::IO_IGNORE; | return self::IO_NONE; | ||||
| } | } | ||||
| public function getDisplayURI() { | public function getDisplayURI() { | ||||
| $uri = new PhutilURI($this->getURI()); | $uri = new PhutilURI($this->getURI()); | ||||
| $protocol = $this->getForcedProtocol(); | $protocol = $this->getForcedProtocol(); | ||||
| if ($protocol) { | if ($protocol) { | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | switch ($this->getBuiltinIdentifier()) { | ||||
| return "/source/{$short_name}{$suffix}"; | return "/source/{$short_name}{$suffix}"; | ||||
| case self::BUILTIN_IDENTIFIER_CALLSIGN: | case self::BUILTIN_IDENTIFIER_CALLSIGN: | ||||
| return "/diffusion/{$callsign}/{$clone_name}{$suffix}"; | return "/diffusion/{$callsign}/{$clone_name}{$suffix}"; | ||||
| default: | default: | ||||
| return null; | return null; | ||||
| } | } | ||||
| } | } | ||||
| /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | |||||
| public function getApplicationTransactionEditor() { | |||||
| return new DiffusionURIEditor(); | |||||
| } | |||||
| public function getApplicationTransactionObject() { | |||||
| return $this; | |||||
| } | |||||
| public function getApplicationTransactionTemplate() { | |||||
| return new PhabricatorRepositoryURITransaction(); | |||||
| } | |||||
| public function willRenderTimeline( | |||||
| PhabricatorApplicationTransactionView $timeline, | |||||
| AphrontRequest $request) { | |||||
| return $timeline; | |||||
| } | |||||
| /* -( PhabricatorPolicyInterface )----------------------------------------- */ | |||||
| public function getCapabilities() { | |||||
| return array( | |||||
| PhabricatorPolicyCapability::CAN_VIEW, | |||||
| PhabricatorPolicyCapability::CAN_EDIT, | |||||
| ); | |||||
| } | |||||
| public function getPolicy($capability) { | |||||
| switch ($capability) { | |||||
| case PhabricatorPolicyCapability::CAN_VIEW: | |||||
| case PhabricatorPolicyCapability::CAN_EDIT: | |||||
| return PhabricatorPolicies::getMostOpenPolicy(); | |||||
| } | |||||
| } | |||||
| public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { | |||||
| return false; | |||||
| } | |||||
| public function describeAutomaticCapability($capability) { | |||||
| return null; | |||||
| } | |||||
| /* -( PhabricatorExtendedPolicyInterface )--------------------------------- */ | |||||
| public function getExtendedPolicy($capability, PhabricatorUser $viewer) { | |||||
| $extended = array(); | |||||
| switch ($capability) { | |||||
| case PhabricatorPolicyCapability::CAN_EDIT: | |||||
| // To edit a repository URI, you must be able to edit the | |||||
| // corresponding repository. | |||||
| $extended[] = array($this->getRepository(), $capability); | |||||
| break; | |||||
| } | |||||
| return $extended; | |||||
| } | |||||
| } | } | ||||