Skip to content

Commit 57d1814

Browse files
update
1 parent f17f141 commit 57d1814

7 files changed

Lines changed: 60 additions & 141 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Supabase\Client\Exceptions;
5+
6+
use RuntimeException;
7+
8+
class InvalidProjectUrlException extends RuntimeException
9+
{
10+
//
11+
}

src/Supabase/Functions.php

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/Supabase/Http/Response.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44

55
namespace Supabase\Client\Http;
66

7-
use Psr\Http\Message\ResponseInterface;
8-
use JsonException;
9-
107
class Response
118
{
12-
private ResponseInterface $response;
9+
public function __construct(
10+
protected string $body,
11+
protected int $status,
12+
protected array $headers = []
13+
) {}
1314

14-
public function __construct(ResponseInterface $response)
15+
public function json(): array|null
1516
{
16-
$this->response = $response;
17-
}
18-
19-
public function json(): mixed
20-
{
21-
$content = (string) $this->response->getBody();
22-
23-
return json_decode($content, true, 512, JSON_THROW_ON_ERROR);
17+
return json_decode($this->body, true);
2418
}
2519
}

src/Supabase/QueryBuilder.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Supabase/Supabase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Supabase\Client\Http\CurlClient;
88
use Supabase\Client\Http\Request;
99
use Supabase\Client\Query\QueryBuilder;
10+
use Supabase\Client\Validation\ProjectUrlValidator;
11+
1012

1113
class Supabase
1214
{
@@ -16,6 +18,7 @@ public function __construct(
1618
private string $url,
1719
private string $token
1820
) {
21+
ProjectUrlValidator::Validate($this->url);
1922
$this->request = new Request(
2023
new CurlClient()
2124
);

src/Supabase/Validation/ProjectUrlValidator.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,50 @@
88

99
class ProjectUrlValidator
1010
{
11-
public static function validate(string $url): void
12-
{
13-
if (!filter_var($url, FILTER_VALIDATE_URL)) {
11+
public static function validate(
12+
string $url
13+
): void {
14+
if (!filter_var(
15+
$url,
16+
FILTER_VALIDATE_URL
17+
)) {
1418
throw new InvalidProjectUrlException(
15-
'Invalid Supabase project URL.'
19+
'Invalid project URL.'
1620
);
1721
}
1822

19-
if (!str_contains($url, '.supabase.co')) {
23+
$parts = parse_url($url);
24+
25+
/*
26+
|--------------------------------------------------------------------------
27+
| HTTPS Required
28+
|--------------------------------------------------------------------------
29+
*/
30+
31+
if (
32+
!isset($parts['scheme']) ||
33+
strtolower($parts['scheme']) !== 'https'
34+
) {
35+
throw new InvalidProjectUrlException(
36+
'Supabase URL must use HTTPS.'
37+
);
38+
}
39+
40+
/*
41+
|--------------------------------------------------------------------------
42+
| Valid Supabase Domain
43+
|--------------------------------------------------------------------------
44+
*/
45+
46+
if (
47+
!isset($parts['host']) ||
48+
!str_ends_with(
49+
$parts['host'],
50+
'.supabase.co'
51+
)
52+
) {
2053
throw new InvalidProjectUrlException(
21-
'Invalid Supabase domain.'
54+
'Invalid Supabase project domain.'
2255
);
2356
}
2457
}

0 commit comments

Comments
 (0)