Skip to content

Commit 7c84cb0

Browse files
Supabase client for php: v3.0.0
1 parent e12c1ff commit 7c84cb0

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

index.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
<?php
22

33
require __dir__.'/vendor/autoload.php';
4-
use Supabase\Client;
54

6-
$client = Client::connect();
7-
$client->setURL('https://supabase.co');
8-
$client->setApiKey('fsvbg');
5+
use Dotenv\Dotenv;
6+
7+
$dotenv = Dotenv::createImmutable(__DIR__);
8+
$dotenv->load();
9+
10+
$url = $_ENV['SB_URL'];
11+
$key = $_ENV['SB_API_KEY'];
12+
13+
$url2 = $url."/rest/v1/users?select=*";
14+
15+
$ch = curl_init();
16+
curl_setopt($ch, CURLOPT_URL, $url2);
17+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
18+
$header = [
19+
'Content-Type: application/json',
20+
"apikey: $key",
21+
"Authorization: Bearer $key",
22+
];
23+
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
24+
25+
$result = curl_exec($ch);
26+
$data = json_decode($result, true);
27+
28+
print('<pre>');
29+
print_r($data);
30+
print('</pre>');

src/t.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Fetch\Interfaces\Response as ResponseInterface;
4+
5+
$data = null;
6+
7+
async(fn () => fetch()
8+
->baseUri('https://example.com')
9+
->withHeaders('Content-Type', 'application/json')
10+
->withBody(['key' => 'value'])
11+
->withToken('fake-bearer-auth-token')
12+
->post('/posts'))
13+
->then(fn (ResponseInterface $response) => $data = $response->json()) // Success handler
14+
->catch(fn (Throwable $e) => $e->getMessage()); // Error handler
15+
16+
echo $data;
17+
18+
use Fetch\Interfaces\Response as ResponseInterface;
19+
20+
$data = null;
21+
22+
async(fn () => fetch()
23+
->baseUri('https://example.com')
24+
->withQueryParameters(['page' => 1])
25+
->withToken('fake-bearer-auth-token')
26+
->get('/resources'))
27+
->then(fn (ResponseInterface $response) => $data = $response->json()) // Success handler
28+
->catch(fn (Throwable $e) => $e->getMessage()); // Error handler
29+
30+
echo $data;

0 commit comments

Comments
 (0)