Skip to content

Commit

Permalink
Merge pull request #131 from ToshY/feature/130
Browse files Browse the repository at this point in the history
Changed Region to backed enum
  • Loading branch information
ToshY authored Aug 26, 2024
2 parents 7ba3f29 + e3e8092 commit 8cab87d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
3 changes: 2 additions & 1 deletion docs/edge-storage-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $bunnyClient = new BunnyClient(
// Provide the "(Read-Only) Password" available at the "FTP & API Access" section of your specific storage zone.
$edgeStorageApi = new EdgeStorageAPI(
apiKey: '6bf3d93a-5078-4d65-a437-501c44576fe6',
region: Region::FS,
client: $bunnyClient,
region: Region::FS,
);
```

Expand All @@ -36,6 +36,7 @@ $edgeStorageApi = new EdgeStorageAPI(
- `Region::SYD` = Sydney (Oceania)
- `Region::BR` = Sao Paolo (Brazil)
- `Region::JH` = Johannesburg (Africa)
- The `Region` is a backed enum, so you can supply a value to the `Region::from` or `Region::tryFrom` method to retrieve the corresponding case.

## Usage

Expand Down
43 changes: 21 additions & 22 deletions src/Enum/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,59 @@

namespace ToshY\BunnyNet\Enum;

enum Region
enum Region: string
{
/** Falkenstein / Frankfurt (Germany) | Main */
case DE;
case FS;
case DE = 'DE';
case FS = 'FS';

/** London (United Kingdom) | Main */
case UK;
case UK = 'UK';

/** Norway (Stockholm) | Main */
case SE;
case SE = 'SE';

/** Prague (Czech Republic) */
case CZ;
case CZ = 'CZ';

/** Madrid (Spain) */
case ES;
case ES = 'ES';

/** New York (United States East) | Main */
case NY;
case NY = 'NY';

/** Los Angeles (United States West) | Main */
case LA;
case LA = 'LA';

/** Seattle (United States West) */
case WA;
case WA = 'WA';

/** Miami (United States East) */
case MI;
case MI = 'MI';

/** Singapore (Singapore) | Main */
case SG;
case SG = 'SG';

/** Hong Kong (SAR of China) */
case HK;
case HK = 'HK';

/** Tokyo (Japan) */
case JP;
case JP = 'JP';

/** Sydney (Oceania) | Main */
case SYD;
case SYD = 'SYD';

/** Sao Paolo (Brazil) | Main */
case BR;
case BR = 'BR';

/** Johannesburg (Africa) | Main */
case JH;
case JH = 'JH';

public function host(): string
{
$subdomain = sprintf('%s.', strtolower($this->name));
if (in_array($this->name, [self::DE->name, self::FS->name], true) === true) {
$subdomain = '';
}
return $subdomain . Host::STORAGE_ENDPOINT;
return match ($this) {
self::DE, self::FS => Host::STORAGE_ENDPOINT,
default => sprintf('%s.%s', strtolower($this->value), Host::STORAGE_ENDPOINT),
};
}
}

0 comments on commit 8cab87d

Please sign in to comment.