[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/almanac/storage/ -> AlmanacDevice.php (source)

   1  <?php
   2  
   3  final class AlmanacDevice
   4    extends AlmanacDAO
   5    implements
   6      PhabricatorPolicyInterface,
   7      PhabricatorCustomFieldInterface,
   8      PhabricatorApplicationTransactionInterface,
   9      PhabricatorProjectInterface,
  10      PhabricatorSSHPublicKeyInterface,
  11      AlmanacPropertyInterface {
  12  
  13    protected $name;
  14    protected $nameIndex;
  15    protected $mailKey;
  16    protected $viewPolicy;
  17    protected $editPolicy;
  18  
  19    private $customFields = self::ATTACHABLE;
  20    private $almanacProperties = self::ATTACHABLE;
  21  
  22    public static function initializeNewDevice() {
  23      return id(new AlmanacDevice())
  24        ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
  25        ->setEditPolicy(PhabricatorPolicies::POLICY_ADMIN)
  26        ->attachAlmanacProperties(array());
  27    }
  28  
  29    public function getConfiguration() {
  30      return array(
  31        self::CONFIG_AUX_PHID => true,
  32        self::CONFIG_COLUMN_SCHEMA => array(
  33          'name' => 'text128',
  34          'nameIndex' => 'bytes12',
  35          'mailKey' => 'bytes20',
  36        ),
  37        self::CONFIG_KEY_SCHEMA => array(
  38          'key_name' => array(
  39            'columns' => array('nameIndex'),
  40            'unique' => true,
  41          ),
  42          'key_nametext' => array(
  43            'columns' => array('name'),
  44          ),
  45        ),
  46      ) + parent::getConfiguration();
  47    }
  48  
  49    public function generatePHID() {
  50      return PhabricatorPHID::generateNewPHID(AlmanacDevicePHIDType::TYPECONST);
  51    }
  52  
  53    public function save() {
  54      AlmanacNames::validateServiceOrDeviceName($this->getName());
  55  
  56      $this->nameIndex = PhabricatorHash::digestForIndex($this->getName());
  57  
  58      if (!$this->mailKey) {
  59        $this->mailKey = Filesystem::readRandomCharacters(20);
  60      }
  61  
  62      return parent::save();
  63    }
  64  
  65    public function getURI() {
  66      return '/almanac/device/view/'.$this->getName().'/';
  67    }
  68  
  69  
  70  /* -(  AlmanacPropertyInterface  )------------------------------------------- */
  71  
  72  
  73    public function attachAlmanacProperties(array $properties) {
  74      assert_instances_of($properties, 'AlmanacProperty');
  75      $this->almanacProperties = mpull($properties, null, 'getFieldName');
  76      return $this;
  77    }
  78  
  79    public function getAlmanacProperties() {
  80      return $this->assertAttached($this->almanacProperties);
  81    }
  82  
  83    public function hasAlmanacProperty($key) {
  84      $this->assertAttached($this->almanacProperties);
  85      return isset($this->almanacProperties[$key]);
  86    }
  87  
  88    public function getAlmanacProperty($key) {
  89      return $this->assertAttachedKey($this->almanacProperties, $key);
  90    }
  91  
  92    public function getAlmanacPropertyValue($key, $default = null) {
  93      if ($this->hasAlmanacProperty($key)) {
  94        return $this->getAlmanacProperty($key)->getFieldValue();
  95      } else {
  96        return $default;
  97      }
  98    }
  99  
 100  
 101  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
 102  
 103  
 104    public function getCapabilities() {
 105      return array(
 106        PhabricatorPolicyCapability::CAN_VIEW,
 107        PhabricatorPolicyCapability::CAN_EDIT,
 108      );
 109    }
 110  
 111    public function getPolicy($capability) {
 112      switch ($capability) {
 113        case PhabricatorPolicyCapability::CAN_VIEW:
 114          return $this->getViewPolicy();
 115        case PhabricatorPolicyCapability::CAN_EDIT:
 116          return $this->getEditPolicy();
 117      }
 118    }
 119  
 120    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
 121      return false;
 122    }
 123  
 124    public function describeAutomaticCapability($capability) {
 125      return null;
 126    }
 127  
 128  
 129  /* -(  PhabricatorCustomFieldInterface  )------------------------------------ */
 130  
 131  
 132    public function getCustomFieldSpecificationForRole($role) {
 133      return array();
 134    }
 135  
 136    public function getCustomFieldBaseClass() {
 137      return 'AlmanacCustomField';
 138    }
 139  
 140    public function getCustomFields() {
 141      return $this->assertAttached($this->customFields);
 142    }
 143  
 144    public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
 145      $this->customFields = $fields;
 146      return $this;
 147    }
 148  
 149  
 150  /* -(  PhabricatorApplicationTransactionInterface  )------------------------- */
 151  
 152  
 153    public function getApplicationTransactionEditor() {
 154      return new AlmanacDeviceEditor();
 155    }
 156  
 157    public function getApplicationTransactionObject() {
 158      return $this;
 159    }
 160  
 161    public function getApplicationTransactionTemplate() {
 162      return new AlmanacDeviceTransaction();
 163    }
 164  
 165  
 166  /* -(  PhabricatorSSHPublicKeyInterface  )----------------------------------- */
 167  
 168  
 169    public function getSSHPublicKeyManagementURI(PhabricatorUser $viewer) {
 170      return $this->getURI();
 171    }
 172  
 173    public function getSSHKeyDefaultName() {
 174      return $this->getName();
 175    }
 176  
 177  
 178  }


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