How samiaraboglu/pubg-php-api works
Project type and purpose
• This is a PHP client library (wrapper) for the PUBG REST API.
• Its goal is to provide PHP services (Player, Season, Match, etc.) that fetch and model PUBG data.
File structure
• src/Config.php and src/Api.php form the core configuration and HTTP request engine.
• Service classes at src/Player.php, src/Season.php, src/Lifetime.php, src/Match.php, src/Leaderboard.php, src/Tournament.php, src/Sample.php each encapsulate one REST resource.
• Domain model classes under src/Object/* (Leaderboard.php, Lifetime.php, Match.php, Player.php, Sample.php, Season.php, Tournament.php) represent parsed API responses.
README for insights
• Configuration flow: instantiate Pubg\Config → set API key & platform → inject into Pubg\Api.
• Each service (e.g. new Pubg\Player($api)) uses Pubg\Api to make calls.
• Services return model objects or collections of model objects.
Main components & their interactions
a. Core Layer
• Config (stores API key, platform, region)
• Api (HTTP client, builds URLs, sets headers, handles responses/exceptions)
b. Service Layer
• PlayerService, SeasonService, LifetimeService, MatchService, LeaderboardService, TournamentService, SampleService
• Dependency: each service holds a reference to Api
c. Domain Model Layer
• Objects in src/Object: classes that map JSON payloads to PHP properties
d. External System
• PUBG REST API endpoints
Relationships & data flow:
1. The application code creates a Config object and populates it.
2. Config is passed to Api, which uses an HTTP client (cURL or Guzzle) to call the external PUBG API.
3. Service classes call Api methods (GET endpoints) based on resource paths (e.g., /players/{id}).
4. Api returns raw JSON; services delegate JSON to the appropriate constructor or factory in the Domain Model layer.
5. Domain objects are returned to the caller.
Architectural patterns & design principles
• Dependency Injection: services receive Api via constructor.
• Single Responsibility: each service handles one resource type.
• Layered Architecture: Core → Services → Models.
• Data Mapping: JSON → Domain Objects.