Path: blob/master/src/applications/passphrase/keys/PassphraseAbstractKey.php
12256 views
<?php12abstract class PassphraseAbstractKey extends Phobject {34private $credential;56protected function requireCredential() {7if (!$this->credential) {8throw new Exception(pht('Credential is required!'));9}10return $this->credential;11}1213private function loadCredential(14$phid,15PhabricatorUser $viewer) {1617$credential = id(new PassphraseCredentialQuery())18->setViewer($viewer)19->withPHIDs(array($phid))20->needSecrets(true)21->executeOne();2223if (!$credential) {24throw new Exception(pht('Failed to load credential "%s"!', $phid));25}2627return $credential;28}2930private function validateCredential(31PassphraseCredential $credential,32$provides_type) {3334$type = $credential->getImplementation();3536if (!$type) {37throw new Exception(38pht(39'Credential "%s" is of unknown type "%s"!',40$credential->getMonogram(),41$credential->getCredentialType()));42}4344if ($type->getProvidesType() !== $provides_type) {45throw new Exception(46pht(47'Credential "%s" must provide "%s", but provides "%s"!',48$credential->getMonogram(),49$provides_type,50$type->getProvidesType()));51}52}5354protected function loadAndValidateFromPHID(55$phid,56PhabricatorUser $viewer,57$type) {5859$credential = $this->loadCredential($phid, $viewer);6061$this->validateCredential($credential, $type);6263$this->credential = $credential;6465return $this;66}6768public function getUsernameEnvelope() {69$credential = $this->requireCredential();70return new PhutilOpaqueEnvelope($credential->getUsername());71}7273}747576