|
1 | 1 | <?php |
| 2 | + |
2 | 3 | declare(strict_types=1); |
3 | 4 |
|
4 | 5 | namespace Supabase\Client; |
5 | | -use Supabase\Client\Supabase; |
6 | 6 |
|
7 | 7 | class Functions extends Supabase |
8 | 8 | { |
9 | | - public function getAllData(?string $table=null) |
10 | | - { |
11 | | - if (!isset($table)) { |
12 | | - echo "Please provide your Supabase table name."; |
13 | | - } else { |
14 | | - $path = "$this->url/$table"; |
15 | | - $html = $this->grab($path, "GET"); |
16 | | - $data = json_decode($html, true); |
17 | | - return $data; |
| 9 | + public function getAllData(?string $table = null) |
| 10 | + { |
| 11 | + if (! isset($table)) { |
| 12 | + echo 'Please provide your Supabase table name.'; |
| 13 | + } else { |
| 14 | + $path = "$this->url/$table"; |
| 15 | + $html = $this->grab($path, 'GET'); |
| 16 | + $data = json_decode($html, true); |
| 17 | + |
| 18 | + return $data; |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + public function getSingleData(?string $table = null, array $query = []) |
| 23 | + { |
| 24 | + if (! isset($table)) { |
| 25 | + echo 'Please provide your Supabase table name.'; |
| 26 | + } elseif (! isset($query)) { |
| 27 | + echo 'Please provide your column name.'; |
| 28 | + } else { |
| 29 | + $path = "$this->url/$table?select=$query"; |
| 30 | + $html = $this->grab($path, 'GET'); |
| 31 | + $data = json_decode($html, true); |
| 32 | + |
| 33 | + return $data; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public function postData(?string $table = null, array $query = [], ?string $on_conflict = null) |
| 38 | + { |
| 39 | + if (! isset($table)) { |
| 40 | + echo 'Please provide your Supabase table name.'; |
| 41 | + } elseif (! isset($query)) { |
| 42 | + echo 'Please provide your data.'; |
| 43 | + } else { |
| 44 | + // If $on_conflict is provided, append to the path |
| 45 | + if (! empty($on_conflict)) { |
| 46 | + $path = "$this->url/$table?on_conflict=$on_conflict"; |
| 47 | + } else { |
| 48 | + $path = "$this->url/$table"; |
| 49 | + } |
| 50 | + |
| 51 | + $html = $this->grab($path, 'POST', json_encode($query)); |
| 52 | + |
| 53 | + return $html; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + public function updateData(?string $table = null, ?int $id = null, array $query = []) |
| 58 | + { |
| 59 | + if (! isset($table)) { |
| 60 | + echo 'Please provide your Supabase table name.'; |
| 61 | + } elseif (! isset($id)) { |
| 62 | + echo 'Please provide id.'; |
| 63 | + } elseif (! isset($query)) { |
| 64 | + echo 'Please provide your data.'; |
| 65 | + } else { |
| 66 | + $path = "$this->url/$table?id=eq.$id"; |
| 67 | + $html = $this->grab($path, 'PATCH', json_encode($query)); |
| 68 | + |
| 69 | + return $html; |
| 70 | + } |
18 | 71 | } |
19 | | - } |
20 | | - |
21 | | - public function getSingleData(?string $table=null, array $query=[]) |
22 | | - { |
23 | | - if (!isset($table)) { |
24 | | - echo "Please provide your Supabase table name."; |
25 | | - } elseif(!isset($query)) { |
26 | | - echo "Please provide your column name."; |
27 | | - } else { |
28 | | - $path = "$this->url/$table?select=$query"; |
29 | | - $html = $this->grab($path, "GET"); |
30 | | - $data = json_decode($html, true); |
31 | | - return $data; |
| 72 | + |
| 73 | + public function deleteData(?string $table = null, ?int $id = null) |
| 74 | + { |
| 75 | + if (! isset($table)) { |
| 76 | + echo 'Please provide your Supabase table name.'; |
| 77 | + } elseif (! isset($id)) { |
| 78 | + echo 'Please provide id.'; |
| 79 | + } else { |
| 80 | + $path = "$this->url/$table?id=eq.$id"; |
| 81 | + $html = $this->grab($path, 'DELETE'); |
| 82 | + |
| 83 | + return $html; |
| 84 | + } |
32 | 85 | } |
33 | | - } |
34 | | - |
35 | | - public function postData(?string $table=null, array $query=[], ?string $on_conflict=null) |
36 | | - { |
37 | | - if (!isset($table)) { |
38 | | - echo "Please provide your Supabase table name."; |
39 | | - } elseif (!isset($query)) { |
40 | | - echo "Please provide your data."; |
41 | | - } else { |
42 | | - // If $on_conflict is provided, append to the path |
43 | | - if (!empty($on_conflict)) { |
44 | | - $path = "$this->url/$table?on_conflict=$on_conflict"; |
45 | | - } else { |
46 | | - $path = "$this->url/$table"; |
47 | | - } |
48 | | - |
49 | | - $html = $this->grab($path, "POST", json_encode($query)); |
50 | | - return $html; |
51 | | - } |
52 | | - } |
53 | | - |
54 | | - public function updateData(?string $table=null, ?int $id=null, array $query=[]) |
55 | | - { |
56 | | - if (!isset($table)) { |
57 | | - echo "Please provide your Supabase table name."; |
58 | | - } elseif (!isset($id)) { |
59 | | - echo "Please provide id."; |
60 | | - } elseif (!isset($query)) { |
61 | | - echo "Please provide your data."; |
62 | | - } else { |
63 | | - $path = "$this->url/$table?id=eq.$id"; |
64 | | - $html = $this->grab($path, "PATCH", json_encode($query)); |
65 | | - return $html; |
| 86 | + |
| 87 | + public function pages(?string $table = null) |
| 88 | + { |
| 89 | + $path = "$this->url/$table?select=*"; |
| 90 | + $html = $this->grab($path, 'GET'); |
| 91 | + $data = json_decode($html, true); |
| 92 | + |
| 93 | + return $data; |
66 | 94 | } |
67 | | - } |
68 | | - |
69 | | - public function deleteData(?string $table=null, ?int $id=null) |
70 | | - { |
71 | | - if (!isset($table)) { |
72 | | - echo "Please provide your Supabase table name."; |
73 | | - } elseif (!isset($id)) { |
74 | | - echo "Please provide id."; |
75 | | - } else { |
76 | | - $path = "$this->url/$table?id=eq.$id"; |
77 | | - $html = $this->grab($path, "DELETE"); |
78 | | - return $html; |
| 95 | + |
| 96 | + public function filter(?string $table = null, ?int $range = null) |
| 97 | + { |
| 98 | + $path = "$this->url/$table?id=eq.$range&select=*"; |
| 99 | + $html = $this->grab($path, 'GET'); |
| 100 | + $data = json_decode($html, true); |
| 101 | + |
| 102 | + return $data; |
79 | 103 | } |
80 | | - } |
81 | | - |
82 | | - public function pages(?string $table=null) |
83 | | - { |
84 | | - $path = "$this->url/$table?select=*"; |
85 | | - $html = $this->grab($path, "GET"); |
86 | | - $data = json_decode($html, true); |
87 | | - return $data; |
88 | | - } |
89 | | - |
90 | | - public function filter(?string $table=null, ?int $range=null) |
91 | | - { |
92 | | - $path = "$this->url/$table?id=eq.$range&select=*"; |
93 | | - $html = $this->grab($path, "GET"); |
94 | | - $data = json_decode($html, true); |
95 | | - return $data; |
96 | | - } |
97 | | - |
98 | | - public function matchs(?string $table=null, array $query=[]) |
99 | | - { |
100 | | - $path = "$this->url/$table"; |
101 | | - $html = $this->grab($path, "POST", json_encode($query)); |
102 | | - return $html; |
103 | | - } |
104 | 104 |
|
| 105 | + public function matchs(?string $table = null, array $query = []) |
| 106 | + { |
| 107 | + $path = "$this->url/$table"; |
| 108 | + $html = $this->grab($path, 'POST', json_encode($query)); |
| 109 | + |
| 110 | + return $html; |
| 111 | + } |
105 | 112 | } |
0 commit comments