[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/passphrase/query/ -> PassphraseCredentialQuery.php (source)

   1  <?php
   2  
   3  final class PassphraseCredentialQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $credentialTypes;
   9    private $providesTypes;
  10    private $isDestroyed;
  11    private $allowConduit;
  12  
  13    private $needSecrets;
  14  
  15    public function withIDs(array $ids) {
  16      $this->ids = $ids;
  17      return $this;
  18    }
  19  
  20    public function withPHIDs(array $phids) {
  21      $this->phids = $phids;
  22      return $this;
  23    }
  24  
  25    public function withCredentialTypes(array $credential_types) {
  26      $this->credentialTypes = $credential_types;
  27      return $this;
  28    }
  29  
  30    public function withProvidesTypes(array $provides_types) {
  31      $this->providesTypes = $provides_types;
  32      return $this;
  33    }
  34  
  35    public function withIsDestroyed($destroyed) {
  36      $this->isDestroyed = $destroyed;
  37      return $this;
  38    }
  39  
  40    public function withAllowConduit($allow_conduit) {
  41      $this->allowConduit = $allow_conduit;
  42      return $this;
  43    }
  44  
  45    public function needSecrets($need_secrets) {
  46      $this->needSecrets = $need_secrets;
  47      return $this;
  48    }
  49  
  50    protected function loadPage() {
  51      $table = new PassphraseCredential();
  52      $conn_r = $table->establishConnection('r');
  53  
  54      $rows = queryfx_all(
  55        $conn_r,
  56        'SELECT * FROM %T %Q %Q %Q',
  57        $table->getTableName(),
  58        $this->buildWhereClause($conn_r),
  59        $this->buildOrderClause($conn_r),
  60        $this->buildLimitClause($conn_r));
  61  
  62      return $table->loadAllFromArray($rows);
  63    }
  64  
  65    protected function willFilterPage(array $page) {
  66      if ($this->needSecrets) {
  67        $secret_ids = mpull($page, 'getSecretID');
  68        $secret_ids = array_filter($secret_ids);
  69  
  70        $secrets = array();
  71        if ($secret_ids) {
  72          $secret_objects = id(new PassphraseSecret())->loadAllWhere(
  73            'id IN (%Ld)',
  74            $secret_ids);
  75          foreach ($secret_objects as $secret) {
  76            $secret_data = $secret->getSecretData();
  77            $secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);
  78          }
  79        }
  80  
  81        foreach ($page as $key => $credential) {
  82          $secret_id = $credential->getSecretID();
  83          if (!$secret_id) {
  84            $credential->attachSecret(null);
  85          } else if (isset($secrets[$secret_id])) {
  86            $credential->attachSecret($secrets[$secret_id]);
  87          } else {
  88            unset($page[$key]);
  89          }
  90        }
  91      }
  92  
  93      return $page;
  94    }
  95  
  96    private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  97      $where = array();
  98  
  99      $where[] = $this->buildPagingClause($conn_r);
 100  
 101      if ($this->ids) {
 102        $where[] = qsprintf(
 103          $conn_r,
 104          'id IN (%Ld)',
 105          $this->ids);
 106      }
 107  
 108      if ($this->phids) {
 109        $where[] = qsprintf(
 110          $conn_r,
 111          'phid IN (%Ls)',
 112          $this->phids);
 113      }
 114  
 115      if ($this->credentialTypes) {
 116        $where[] = qsprintf(
 117          $conn_r,
 118          'credentialType in (%Ls)',
 119          $this->credentialTypes);
 120      }
 121  
 122      if ($this->providesTypes) {
 123        $where[] = qsprintf(
 124          $conn_r,
 125          'providesType IN (%Ls)',
 126          $this->providesTypes);
 127      }
 128  
 129      if ($this->isDestroyed !== null) {
 130        $where[] = qsprintf(
 131          $conn_r,
 132          'isDestroyed = %d',
 133          (int)$this->isDestroyed);
 134      }
 135  
 136      if ($this->allowConduit !== null) {
 137        $where[] = qsprintf(
 138          $conn_r,
 139          'allowConduit = %d',
 140          (int)$this->allowConduit);
 141      }
 142  
 143      return $this->formatWhereClause($where);
 144    }
 145  
 146    public function getQueryApplicationClass() {
 147      return 'PhabricatorPassphraseApplication';
 148    }
 149  
 150  }


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