Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / query / AlmanacPropertyQuery.php
blob4261c70fec48119dc28cc72ae91dbc75f799a94a
1 <?php
3 final class AlmanacPropertyQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $objectPHIDs;
8 private $objects;
9 private $names;
11 public function withIDs(array $ids) {
12 $this->ids = $ids;
13 return $this;
16 public function withObjectPHIDs(array $phids) {
17 $this->objectPHIDs = $phids;
18 return $this;
21 public function withObjects(array $objects) {
22 $this->objects = mpull($objects, null, 'getPHID');
23 $this->objectPHIDs = array_keys($this->objects);
24 return $this;
27 public function withNames(array $names) {
28 $this->names = $names;
29 return $this;
32 public function newResultObject() {
33 return new AlmanacProperty();
36 protected function willFilterPage(array $properties) {
37 $object_phids = mpull($properties, 'getObjectPHID');
39 $object_phids = array_fuse($object_phids);
41 if ($this->objects !== null) {
42 $object_phids = array_diff_key($object_phids, $this->objects);
45 if ($object_phids) {
46 $objects = id(new PhabricatorObjectQuery())
47 ->setViewer($this->getViewer())
48 ->setParentQuery($this)
49 ->withPHIDs($object_phids)
50 ->execute();
51 $objects = mpull($objects, null, 'getPHID');
52 } else {
53 $objects = array();
56 $objects += $this->objects;
58 foreach ($properties as $key => $property) {
59 $object = idx($objects, $property->getObjectPHID());
60 if (!$object) {
61 unset($properties[$key]);
62 continue;
64 $property->attachObject($object);
67 return $properties;
70 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
71 $where = parent::buildWhereClauseParts($conn);
73 if ($this->ids !== null) {
74 $where[] = qsprintf(
75 $conn,
76 'id IN (%Ld)',
77 $this->ids);
80 if ($this->objectPHIDs !== null) {
81 $where[] = qsprintf(
82 $conn,
83 'objectPHID IN (%Ls)',
84 $this->objectPHIDs);
87 if ($this->names !== null) {
88 $hashes = array();
89 foreach ($this->names as $name) {
90 $hashes[] = PhabricatorHash::digestForIndex($name);
92 $where[] = qsprintf(
93 $conn,
94 'fieldIndex IN (%Ls)',
95 $hashes);
98 return $where;
101 public function getQueryApplicationClass() {
102 return 'PhabricatorAlmanacApplication';