Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / conduit / query / PhabricatorConduitTokenQuery.php
blob384efccadfdf74f78933acbf275094f79daeda09
1 <?php
3 final class PhabricatorConduitTokenQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $objectPHIDs;
8 private $expired;
9 private $tokens;
10 private $tokenTypes;
12 public function withExpired($expired) {
13 $this->expired = $expired;
14 return $this;
17 public function withIDs(array $ids) {
18 $this->ids = $ids;
19 return $this;
22 public function withObjectPHIDs(array $phids) {
23 $this->objectPHIDs = $phids;
24 return $this;
27 public function withTokens(array $tokens) {
28 $this->tokens = $tokens;
29 return $this;
32 public function withTokenTypes(array $types) {
33 $this->tokenTypes = $types;
34 return $this;
37 public function newResultObject() {
38 return new PhabricatorConduitToken();
41 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
42 $where = parent::buildWhereClauseParts($conn);
44 if ($this->ids !== null) {
45 $where[] = qsprintf(
46 $conn,
47 'id IN (%Ld)',
48 $this->ids);
51 if ($this->objectPHIDs !== null) {
52 $where[] = qsprintf(
53 $conn,
54 'objectPHID IN (%Ls)',
55 $this->objectPHIDs);
58 if ($this->tokens !== null) {
59 $where[] = qsprintf(
60 $conn,
61 'token IN (%Ls)',
62 $this->tokens);
65 if ($this->tokenTypes !== null) {
66 $where[] = qsprintf(
67 $conn,
68 'tokenType IN (%Ls)',
69 $this->tokenTypes);
72 if ($this->expired !== null) {
73 if ($this->expired) {
74 $where[] = qsprintf(
75 $conn,
76 'expires <= %d',
77 PhabricatorTime::getNow());
78 } else {
79 $where[] = qsprintf(
80 $conn,
81 'expires IS NULL OR expires > %d',
82 PhabricatorTime::getNow());
86 return $where;
89 protected function willFilterPage(array $tokens) {
90 $object_phids = mpull($tokens, 'getObjectPHID');
91 $objects = id(new PhabricatorObjectQuery())
92 ->setViewer($this->getViewer())
93 ->setParentQuery($this)
94 ->withPHIDs($object_phids)
95 ->execute();
96 $objects = mpull($objects, null, 'getPHID');
98 foreach ($tokens as $key => $token) {
99 $object = idx($objects, $token->getObjectPHID(), null);
100 if (!$object) {
101 $this->didRejectResult($token);
102 unset($tokens[$key]);
103 continue;
105 $token->attachObject($object);
108 return $tokens;
111 public function getQueryApplicationClass() {
112 return 'PhabricatorConduitApplication';