Skip to content

Commit a00d3f2

Browse files
Handling regions with getRegionFromSpaceId (#11)
* Handling regions with getRegionFromSpaceId
1 parent 4580405 commit a00d3f2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/StoryblokUtils.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@
66

77
class StoryblokUtils
88
{
9+
private const array ALL_REGION_RANGES = [
10+
'EU' => [0, 999_999],
11+
// 'CN' => [0, 1_000_000],
12+
'US' => [1_000_000, 1_999_999],
13+
'CA' => [2_000_000, 2_999_999],
14+
'AP' => [3_000_000, 3_999_999],
15+
];
16+
917
public static function getRegionFromSpaceId(string|int $spaceId): string
1018
{
11-
return ($spaceId >= 1_000_000) ? "US" : "EU";
19+
foreach (self::ALL_REGION_RANGES as $region => [$min, $max]) {
20+
if ($spaceId >= $min && $spaceId < $max) {
21+
return $region;
22+
}
23+
}
24+
25+
return 'EU'; // fallback in case the ID doesn't match any range
1226
}
1327

1428
/**

tests/Unit/StoryblokUtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
})->with([
1010
['1000', 'EU'],
1111
['10000', 'EU'],
12-
[100_000_000, 'US'],
12+
[1_000_000, 'US'],
1313
]);
1414

1515
test('Testing baseUriFromRegionForMapi', function ($region, $baseUri): void {

0 commit comments

Comments
 (0)