[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/passphrase/storage/ -> PassphraseCredential.php (source)

   1  <?php
   2  
   3  final class PassphraseCredential extends PassphraseDAO
   4    implements PhabricatorPolicyInterface,
   5    PhabricatorDestructibleInterface {
   6  
   7    protected $name;
   8    protected $credentialType;
   9    protected $providesType;
  10    protected $viewPolicy;
  11    protected $editPolicy;
  12    protected $description;
  13    protected $username;
  14    protected $secretID;
  15    protected $isDestroyed;
  16    protected $isLocked = 0;
  17    protected $allowConduit = 0;
  18  
  19    private $secret = self::ATTACHABLE;
  20  
  21    public static function initializeNewCredential(PhabricatorUser $actor) {
  22      return id(new PassphraseCredential())
  23        ->setName('')
  24        ->setUsername('')
  25        ->setDescription('')
  26        ->setIsDestroyed(0)
  27        ->setViewPolicy($actor->getPHID())
  28        ->setEditPolicy($actor->getPHID());
  29    }
  30  
  31    public function getMonogram() {
  32      return 'K'.$this->getID();
  33    }
  34  
  35    public function getConfiguration() {
  36      return array(
  37        self::CONFIG_AUX_PHID => true,
  38        self::CONFIG_COLUMN_SCHEMA => array(
  39          'name' => 'text255',
  40          'credentialType' => 'text64',
  41          'providesType' => 'text64',
  42          'description' => 'text',
  43          'username' => 'text255',
  44          'secretID' => 'id?',
  45          'isDestroyed' => 'bool',
  46          'isLocked' => 'bool',
  47          'allowConduit' => 'bool',
  48        ),
  49        self::CONFIG_KEY_SCHEMA => array(
  50          'key_secret' => array(
  51            'columns' => array('secretID'),
  52            'unique' => true,
  53          ),
  54          'key_type' => array(
  55            'columns' => array('credentialType'),
  56          ),
  57          'key_provides' => array(
  58            'columns' => array('providesType'),
  59          ),
  60        ),
  61      ) + parent::getConfiguration();
  62    }
  63  
  64    public function generatePHID() {
  65      return PhabricatorPHID::generateNewPHID(
  66        PassphraseCredentialPHIDType::TYPECONST);
  67    }
  68  
  69    public function attachSecret(PhutilOpaqueEnvelope $secret = null) {
  70      $this->secret = $secret;
  71      return $this;
  72    }
  73  
  74    public function getSecret() {
  75      return $this->assertAttached($this->secret);
  76    }
  77  
  78    public function getCredentialTypeImplementation() {
  79      $type = $this->getCredentialType();
  80      return PassphraseCredentialType::getTypeByConstant($type);
  81    }
  82  
  83  
  84  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
  85  
  86  
  87    public function getCapabilities() {
  88      return array(
  89        PhabricatorPolicyCapability::CAN_VIEW,
  90        PhabricatorPolicyCapability::CAN_EDIT,
  91      );
  92    }
  93  
  94    public function getPolicy($capability) {
  95      switch ($capability) {
  96        case PhabricatorPolicyCapability::CAN_VIEW:
  97          return $this->getViewPolicy();
  98        case PhabricatorPolicyCapability::CAN_EDIT:
  99          return $this->getEditPolicy();
 100      }
 101    }
 102  
 103    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
 104      return false;
 105    }
 106  
 107    public function describeAutomaticCapability($capability) {
 108      return null;
 109    }
 110  
 111  /* -(  PhabricatorDestructibleInterface  )----------------------------------- */
 112  
 113    public function destroyObjectPermanently(
 114      PhabricatorDestructionEngine $engine) {
 115  
 116      $this->openTransaction();
 117        $secrets = id(new PassphraseSecret())->loadAllWhere(
 118          'id = %d',
 119          $this->getSecretID());
 120        foreach ($secrets as $secret) {
 121          $secret->delete();
 122        }
 123        $this->delete();
 124      $this->saveTransaction();
 125    }
 126  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1