File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Supabase \Util ;
6+
7+ use Dotenv \Dotenv ;
8+
9+ class EnvSetup
10+ {
11+ public static function env (string $ path ): mixed
12+ {
13+ // If the env vars are set and not empty use them
14+ $ apiKey = getenv ('SB_API_KEY ' );
15+ $ url = getenv ('SB_URL ' );
16+
17+ // else check try to load the .env file in the $path
18+ if (empty ($ apiKey ) || empty ($ url )) {
19+ $ loaded = Dotenv::createArrayBacked ($ path )->safeLoad ();
20+ if (array_key_exists ('SB_API_KEY ' , $ loaded )) {
21+ $ apiKey = $ loaded ['SB_API_KEY ' ];
22+ }
23+
24+ if (array_key_exists ('SB_URL ' , $ loaded )) {
25+ $ url = $ loaded ['SB_URL ' ];
26+ }
27+ }
28+
29+ if (empty ($ apiKey )) {
30+ throw new \Exception ('Could not load API_KEY ' );
31+ }
32+
33+ if (empty ($ url )) {
34+ throw new \Exception ('Could not load URL ' );
35+ }
36+
37+ return [
38+ 'SB_API_KEY ' => $ apiKey ,
39+ 'SB_URL ' => $ url ,
40+ ];
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments