Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / storage / PhabricatorRepositoryRefCursor.php
blobe661e94295cd2843c194e559be8bd0581cbe592c
1 <?php
3 /**
4 * Stores the previous value of a ref (like a branch or tag) so we can figure
5 * out how a repository has changed when we discover new commits or branch
6 * heads.
7 */
8 final class PhabricatorRepositoryRefCursor
9 extends PhabricatorRepositoryDAO
10 implements PhabricatorPolicyInterface {
12 const TYPE_BRANCH = 'branch';
13 const TYPE_TAG = 'tag';
14 const TYPE_BOOKMARK = 'bookmark';
15 const TYPE_REF = 'ref';
17 protected $repositoryPHID;
18 protected $refType;
19 protected $refNameHash;
20 protected $refNameRaw;
21 protected $refNameEncoding;
22 protected $isPermanent;
24 private $repository = self::ATTACHABLE;
25 private $positions = self::ATTACHABLE;
27 protected function getConfiguration() {
28 return array(
29 self::CONFIG_TIMESTAMPS => false,
30 self::CONFIG_AUX_PHID => true,
31 self::CONFIG_BINARY => array(
32 'refNameRaw' => true,
34 self::CONFIG_COLUMN_SCHEMA => array(
35 'refType' => 'text32',
36 'refNameHash' => 'bytes12',
37 'refNameEncoding' => 'text16?',
38 'isPermanent' => 'bool',
40 self::CONFIG_KEY_SCHEMA => array(
41 'key_ref' => array(
42 'columns' => array('repositoryPHID', 'refType', 'refNameHash'),
43 'unique' => true,
46 ) + parent::getConfiguration();
49 public function generatePHID() {
50 return PhabricatorPHID::generateNewPHID(
51 PhabricatorRepositoryRefCursorPHIDType::TYPECONST);
54 public function getRefName() {
55 return $this->getUTF8StringFromStorage(
56 $this->getRefNameRaw(),
57 $this->getRefNameEncoding());
60 public function setRefName($ref_raw) {
61 $this->setRefNameRaw($ref_raw);
62 $this->setRefNameHash(PhabricatorHash::digestForIndex($ref_raw));
63 $this->setRefNameEncoding($this->detectEncodingForStorage($ref_raw));
65 return $this;
68 public function attachRepository(PhabricatorRepository $repository) {
69 $this->repository = $repository;
70 return $this;
73 public function getRepository() {
74 return $this->assertAttached($this->repository);
77 public function attachPositions(array $positions) {
78 assert_instances_of($positions, 'PhabricatorRepositoryRefPosition');
79 $this->positions = $positions;
80 return $this;
83 public function getPositions() {
84 return $this->assertAttached($this->positions);
87 public function getPositionIdentifiers() {
88 return mpull($this->getPositions(), 'getCommitIdentifier');
91 public function newDiffusionRepositoryRef() {
92 return id(new DiffusionRepositoryRef())
93 ->setRefType($this->getRefType())
94 ->setShortName($this->getRefName());
98 /* -( PhabricatorPolicyInterface )----------------------------------------- */
101 public function getCapabilities() {
102 return array(
103 PhabricatorPolicyCapability::CAN_VIEW,
107 public function getPolicy($capability) {
108 return $this->getRepository()->getPolicy($capability);
111 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
112 return $this->getRepository()->hasAutomaticCapability($capability, $viewer);
115 public function describeAutomaticCapability($capability) {
116 return pht('Repository refs have the same policies as their repository.');