How brokeyourbike/western-union-api-client-php works
Project type and purpose
• This is a PHP client library (SDK) for the Western Union REST API.
• It provides a thin wrapper over HTTP calls (via Guzzle) and maps request/responses into strongly‐typed PHP Models and Enums.
File structure
• Top level: configuration files (composer.json, .github/, CI workflows, testing configs).
• src/Client.php: the central orchestration class.
• src/Interfaces/ConfigInterface.php: abstraction for supplying API credentials and endpoints.
• src/Enums: various request‐ or response‐parameter enumerations.
• src/Models: data‐transfer objects mapping the JSON payloads returned by the API.
• tests/: PHPUnit tests verifying client behavior and mapping logic.
Key insights from the README
• Usage snippet shows dependency injection of a ConfigInterface and any GuzzleHttp\ClientInterface.
• The library’s sole external dependency is an HTTP client (Guzzle).
• No internal database or UI components—pure server‐side SDK.
a. Main components:
• Config Provider (implements ConfigInterface)
• HTTP Client (any GuzzleHttp\ClientInterface)
• API Client (Client.php)
• Enums (request/query parameter constraints)
• Models (response payload mapping)
• External Western Union REST API
• Supporting CI/CD (GitHub Actions) and Test Harness (PHPUnit)
b. Relationships & interactions:
1. The application implements ConfigInterface → supplies base URL, credentials.
2. The application injects a GuzzleHttp\ClientInterface → handles HTTP transport.
3. Client uses Config + HTTP Client → constructs requests (including Enums) → sends to Western Union API.
4. API returns JSON → Client maps JSON to Models → returns Models to caller.
5. PHPUnit tests invoke Client with mock HTTP client → assert correct mapping and error‐handling.
6. GitHub Actions workflows run static analysis, tests, and release automation on each commit.
c. Architectural patterns & principles:
• Dependency Injection (ConfigInterface, HTTP Client) for testability & extensibility.
• Single Responsibility: Client only orchestrates calls; Models only hold data; Enums only define constants.
• Layered separation: Configuration → Client orchestration → HTTP transport → Domain Models.
d. Key technologies & libraries:
• PHP 7.4+ (composer metadata in composer.json)
• GuzzleHttp for HTTP transport
• PHPUnit for testing
• PHPStan for static analysis
• GitHub Actions for CI/CD
Being detailed but not overcomplicated
• Every interaction path (normal calls, error flows, test harness).
• Config‐to‐client and client‐to‐HTTP layers are explicitly drawn.