Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/doorkeeper/bridge/DoorkeeperBridge.php
12256 views
1
<?php
2
3
abstract class DoorkeeperBridge extends Phobject {
4
5
private $viewer;
6
private $context = array();
7
private $throwOnMissingLink;
8
private $timeout;
9
10
public function setTimeout($timeout) {
11
$this->timeout = $timeout;
12
return $this;
13
}
14
15
public function getTimeout() {
16
return $this->timeout;
17
}
18
19
public function setThrowOnMissingLink($throw_on_missing_link) {
20
$this->throwOnMissingLink = $throw_on_missing_link;
21
return $this;
22
}
23
24
final public function setViewer($viewer) {
25
$this->viewer = $viewer;
26
return $this;
27
}
28
29
final public function getViewer() {
30
return $this->viewer;
31
}
32
33
final public function setContext($context) {
34
$this->context = $context;
35
return $this;
36
}
37
38
final public function getContextProperty($key, $default = null) {
39
return idx($this->context, $key, $default);
40
}
41
42
public function isEnabled() {
43
return true;
44
}
45
46
abstract public function canPullRef(DoorkeeperObjectRef $ref);
47
abstract public function pullRefs(array $refs);
48
49
public function fillObjectFromData(DoorkeeperExternalObject $obj, $result) {
50
return;
51
}
52
53
public function didFailOnMissingLink() {
54
if ($this->throwOnMissingLink) {
55
throw new DoorkeeperMissingLinkException();
56
}
57
58
return null;
59
}
60
61
final protected function saveExternalObject(
62
DoorkeeperObjectRef $ref,
63
DoorkeeperExternalObject $obj) {
64
65
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
66
try {
67
$obj->save();
68
} catch (AphrontDuplicateKeyQueryException $ex) {
69
70
// In various cases, we may race another process importing the same
71
// data. If we do, we'll collide on the object key. Load the object
72
// the other process created and use that.
73
$obj = id(new DoorkeeperExternalObjectQuery())
74
->setViewer($this->getViewer())
75
->withObjectKeys(array($ref->getObjectKey()))
76
->executeOne();
77
if (!$obj) {
78
throw new PhutilProxyException(
79
pht('Failed to load external object after collision.'),
80
$ex);
81
}
82
83
$ref->attachExternalObject($obj);
84
}
85
unset($unguarded);
86
}
87
88
89
}
90
91