Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / query / PhabricatorQuery.php
blobf4ce35adaf0c234b62d350e91ed41707276e6dd4
1 <?php
3 /**
4 * @task format Formatting Query Clauses
5 */
6 abstract class PhabricatorQuery extends Phobject {
9 abstract public function execute();
12 /* -( Formatting Query Clauses )------------------------------------------- */
15 /**
16 * @task format
18 protected function formatWhereClause(
19 AphrontDatabaseConnection $conn,
20 array $parts) {
22 $parts = $this->flattenSubclause($parts);
23 if (!$parts) {
24 return qsprintf($conn, '');
27 return qsprintf($conn, 'WHERE %LA', $parts);
32 /**
33 * @task format
35 protected function formatSelectClause(
36 AphrontDatabaseConnection $conn,
37 array $parts) {
39 $parts = $this->flattenSubclause($parts);
40 if (!$parts) {
41 throw new Exception(pht('Can not build empty SELECT clause!'));
44 return qsprintf($conn, 'SELECT %LQ', $parts);
48 /**
49 * @task format
51 protected function formatJoinClause(
52 AphrontDatabaseConnection $conn,
53 array $parts) {
55 $parts = $this->flattenSubclause($parts);
56 if (!$parts) {
57 return qsprintf($conn, '');
60 return qsprintf($conn, '%LJ', $parts);
64 /**
65 * @task format
67 protected function formatHavingClause(
68 AphrontDatabaseConnection $conn,
69 array $parts) {
71 $parts = $this->flattenSubclause($parts);
72 if (!$parts) {
73 return qsprintf($conn, '');
76 return qsprintf($conn, 'HAVING %LA', $parts);
80 /**
81 * @task format
83 private function flattenSubclause(array $parts) {
84 $result = array();
85 foreach ($parts as $part) {
86 if (is_array($part)) {
87 foreach ($this->flattenSubclause($part) as $subpart) {
88 $result[] = $subpart;
90 } else if (($part !== null) && strlen($part)) {
91 $result[] = $part;
94 return $result;