Download the PHP package matthiggins/bluezone without Composer
On this page you can find all versions of the php package matthiggins/bluezone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download matthiggins/bluezone
More information about matthiggins/bluezone
Files in matthiggins/bluezone
Package bluezone
Short Description A modern PHP SDK for the PUBG API and PUBG match telemetry files.
License MIT
Homepage https://github.com/matthiggins/bluezone
Informations about the package bluezone
BLUEZONE : A PHP SDK for the PUBG API
BLUEZONE is a PHP SDK for the PUBG API. It covers players, matches, seasons, clans, ranked and lifetime stats, weapon and survival mastery, and it parses match telemetry files into typed event objects.
It is built on Saloon 4: every response is a data transfer object, and every Saloon feature (mocking, middleware, retries) is available.
Links: PUBG API · PUBG API docs · Saloon · Laravel Collections
Contents
- Requirements
- Installation
- Creating a client
- Rate limiting
- Shards and game modes
- Resources
- Exceptions
- Match telemetry
- Telemetry events
- Testing
Requirements
- PHP 8.3 or 8.4
- Saloon 4 (installed as a dependency)
- A PUBG API key from the PUBG Developer Portal
Installation
Creating a client
The constructor is:
$requestsPerMinute should match the quota on your key (10 for a standard key). Connect and request timeouts are 10s and 15s.
Rate limiting
Bluezone enforces your quota client-side with the Saloon rate limit plugin, so you fail fast instead of burning 429s.
The default store is Saloon's MemoryStore, which only tracks one process. In a queue worker, a web app, or anything else running more than one process at a time, pass a shared store:
LaravelCacheStore and FileStore work as well. Both the spent local budget and a 429 from the API raise Saloon\RateLimitPlugin\Exceptions\RateLimitReachedException; the 429 handler runs first, so Saloon's own TooManyRequestsException is not what you catch.
recentMatches() (and recentCasualMatches() / recentRankedMatches()) issues one request per match id, and rankedSeasonStatsMany() one per account id, so a default $limit of 20 spends twice a standard key's 10-per-minute budget: keep $limit under your per-minute budget, or pass the budget your key actually has.
Turn the plugin off in tests with $bluezone->useRateLimitPlugin(false).
Shards and game modes
Every resource method takes Bluezone\Enums\Shard or its string value, and Bluezone\Enums\GameMode or its string value.
Shards: steam, xbox, psn, kakao, console, tournament. Game modes: solo, solo-fpp, duo, duo-fpp, squad, squad-fpp.
Leaderboards are the one endpoint still keyed by platform-region, so they take Bluezone\Enums\Region (pc-eu, pc-na, pc-as, pc-sea, pc-kakao, …) instead of a shard.
Resources
Every method returns a typed DTO from Bluezone\Responses.
rankedSeasonStatsMany() is one request per account id: the PUBG API has no batch ranked endpoint.
Samples and leaderboards are metered against the rate limit; matches are not. A leaderboard row's kda and killDeathRatio are always 0 from the API, so LeaderboardPlayer leaves them out.
Exceptions
Bluezone throws Bluezone\Exceptions\BluezoneException subclasses for the cases the API reports as a bare 404:
| Exception | Thrown when |
|---|---|
PlayerNotFoundException |
player()->find(), findMany(), search() or searchMany() gets a 404, or the search matched no player |
MatchNotFoundException |
match()->find() gets a 404 |
LeaderboardNotFoundException |
leaderboard()->get() gets a 404: no board for that region, season and mode |
InvalidSampleWindowException |
sample()->get() is given a start time more than 14 days back or in the future; thrown before any request is sent |
InvalidTelemetryUrlException |
a telemetry url is not on telemetry-cdn.pubg.com |
InvalidTelemetryException |
a telemetry body is not decodable JSON |
Saloon\RateLimitPlugin\Exceptions\RateLimitReachedException |
the local budget is spent, or the API answered 429 |
ValueError |
Shard::resolve(), Region::resolve() or GameMode::resolve() is given a string that is not a shard, region or game mode |
Everything else surfaces as a Saloon exception (UnauthorizedException, ServiceUnavailableException, FatalRequestException, …). See Saloon — handling failures.
Match telemetry
Telemetry files are gzipped JSON on a public CDN, typically 5-15 MB, and are downloaded by a separate connector that carries no API key and does not count against your rate limit.
Use download() instead when you want the bytes rather than the objects. It returns the compressed body as a PSR-7 StreamInterface and decodes nothing:
Telemetry events
Events whose _T has no class are skipped rather than failing the parse, and counted by unmappedTypes().
Player events
Match events
Filtering events
events() is a Laravel Collection, so filter it however you like:
Testing
Bluezone is a Saloon connector, so mock it with Saloon's MockClient:
Telemetry downloads go through a second connector (TelemetryConnector), which a MockClient attached to the Bluezone instance does not reach; use MockClient::global([...]) to mock them.
This package's own suite replays recorded responses:
To re-record a fixture, delete the file and run the recording test with a real key:
Run the checks with composer check (Pint, PHPStan level 5, Pest).
All versions of bluezone with dependencies
illuminate/collections Version ^12.0 || ^13.0
nesbot/carbon Version ^3.0
saloonphp/rate-limit-plugin Version ^2.5
saloonphp/saloon Version ^4.0