Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / tokens / query / PhabricatorTokenGivenQuery.php
blob0e6ad9eb548320661109ce6d76f063131bceaa01
1 <?php
3 final class PhabricatorTokenGivenQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $authorPHIDs;
7 private $objectPHIDs;
8 private $tokenPHIDs;
10 public function withTokenPHIDs(array $token_phids) {
11 $this->tokenPHIDs = $token_phids;
12 return $this;
15 public function withObjectPHIDs(array $object_phids) {
16 $this->objectPHIDs = $object_phids;
17 return $this;
20 public function withAuthorPHIDs(array $author_phids) {
21 $this->authorPHIDs = $author_phids;
22 return $this;
25 public function newResultObject() {
26 return new PhabricatorTokenGiven();
29 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
30 $where = parent::buildWhereClauseParts($conn);
32 if ($this->authorPHIDs !== null) {
33 $where[] = qsprintf(
34 $conn,
35 'authorPHID IN (%Ls)',
36 $this->authorPHIDs);
39 if ($this->objectPHIDs !== null) {
40 $where[] = qsprintf(
41 $conn,
42 'objectPHID IN (%Ls)',
43 $this->objectPHIDs);
46 if ($this->tokenPHIDs !== null) {
47 $where[] = qsprintf(
48 $conn,
49 'tokenPHID IN (%Ls)',
50 $this->tokenPHIDs);
53 return $where;
56 protected function willFilterPage(array $results) {
57 $viewer = $this->getViewer();
59 $object_phids = mpull($results, 'getObjectPHID');
61 $objects = id(new PhabricatorObjectQuery())
62 ->setViewer($viewer)
63 ->withPHIDs($object_phids)
64 ->execute();
65 $objects = mpull($objects, null, 'getPHID');
67 foreach ($results as $key => $result) {
68 $object = idx($objects, $result->getObjectPHID());
70 if ($object) {
71 if ($object instanceof PhabricatorTokenReceiverInterface) {
72 $result->attachObject($object);
73 continue;
77 $this->didRejectResult($result);
78 unset($results[$key]);
81 if (!$results) {
82 return $results;
85 $token_phids = mpull($results, 'getTokenPHID');
87 $tokens = id(new PhabricatorTokenQuery())
88 ->setViewer($viewer)
89 ->withPHIDs($token_phids)
90 ->execute();
91 $tokens = mpull($tokens, null, 'getPHID');
93 foreach ($results as $key => $result) {
94 $token_phid = $result->getTokenPHID();
96 $token = idx($tokens, $token_phid);
97 if (!$token) {
98 $this->didRejectResult($result);
99 unset($results[$key]);
100 continue;
103 $result->attachToken($token);
106 return $results;
109 public function getQueryApplicationClass() {
110 return 'PhabricatorTokensApplication';