Path: blob/master/src/applications/doorkeeper/bridge/DoorkeeperBridge.php
12256 views
<?php12abstract class DoorkeeperBridge extends Phobject {34private $viewer;5private $context = array();6private $throwOnMissingLink;7private $timeout;89public function setTimeout($timeout) {10$this->timeout = $timeout;11return $this;12}1314public function getTimeout() {15return $this->timeout;16}1718public function setThrowOnMissingLink($throw_on_missing_link) {19$this->throwOnMissingLink = $throw_on_missing_link;20return $this;21}2223final public function setViewer($viewer) {24$this->viewer = $viewer;25return $this;26}2728final public function getViewer() {29return $this->viewer;30}3132final public function setContext($context) {33$this->context = $context;34return $this;35}3637final public function getContextProperty($key, $default = null) {38return idx($this->context, $key, $default);39}4041public function isEnabled() {42return true;43}4445abstract public function canPullRef(DoorkeeperObjectRef $ref);46abstract public function pullRefs(array $refs);4748public function fillObjectFromData(DoorkeeperExternalObject $obj, $result) {49return;50}5152public function didFailOnMissingLink() {53if ($this->throwOnMissingLink) {54throw new DoorkeeperMissingLinkException();55}5657return null;58}5960final protected function saveExternalObject(61DoorkeeperObjectRef $ref,62DoorkeeperExternalObject $obj) {6364$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();65try {66$obj->save();67} catch (AphrontDuplicateKeyQueryException $ex) {6869// In various cases, we may race another process importing the same70// data. If we do, we'll collide on the object key. Load the object71// the other process created and use that.72$obj = id(new DoorkeeperExternalObjectQuery())73->setViewer($this->getViewer())74->withObjectKeys(array($ref->getObjectKey()))75->executeOne();76if (!$obj) {77throw new PhutilProxyException(78pht('Failed to load external object after collision.'),79$ex);80}8182$ref->attachExternalObject($obj);83}84unset($unguarded);85}868788}899091