royfee / basesdk
A modern PHP SDK foundation package for building API clients with ease.
1.0.1
2026-09-15 14:24 UTC
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^6.2|^7.0
- pimple/pimple: ^3.0
- psr/http-message: ^1.0|^2.0
- psr/log: ^1.0|^2.0|^3.0
- psr/simple-cache: ^1.0|^2.0|^3.0
Requires (Dev)
- guzzlehttp/psr7: ^1.7|^2.0
- monolog/monolog: ^2.0|^3.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.3|^10.0
Suggests
- monolog/monolog: For file-based logging support (^2.0|^3.0).
Provides
None
Conflicts
None
Replaces
None
README
A modern PHP SDK foundation package for building API clients with ease.
Based on hanson/foundation-sdk, redesigned with PSR standards and improved architecture.
Features
| Feature | Description |
|---|---|
| PSR-3 Logging | Standard logger interface, Monolog optional |
| PSR-16 Cache | Built-in file cache, or bring your own |
| HTTP Client | Guzzle wrapper with GET/POST/PUT/PATCH/DELETE/Upload |
| Middleware | Interface-based pipeline with auth & retry built-in |
| Response Wrapper | Auto JSON decode, status helpers |
| Token Management | Auto-cached access token with refresh |
| Dot-notation Config | Access nested config with log.file syntax |
Requirements
- PHP >= 7.4
- ext-curl
- ext-json
Installation
composer require royfee/basesdk
For file-based logging, install Monolog:
composer require monolog/monolog
Quick Start
use Royfee\BaseSdk\Application; use Royfee\BaseSdk\Api\AbstractApi; // 1. Create the application $app = new Application([ 'debug' => true, 'log' => [ 'file' => __DIR__ . '/logs/sdk.log', 'level' => \Monolog\Logger::DEBUG, ], ]); // 2. Define your API class class MyApi extends AbstractApi { protected function getBaseUrl(): string { return 'https://api.example.com/v1'; } protected function getDefaultHeaders(): array { return [ 'Authorization' => 'Bearer ' . $this->app->getConfig('token'), 'Content-Type' => 'application/json', ]; } public function getUsers(): array { $response = $this->getHttp()->postJson( $this->getBaseUrl() . '/users', [], $this->getDefaultHeaders() ); return $response->toArray(); } } // 3. Use it $api = new MyApi($app); $users = $api->getUsers();
Documentation
See the doc/ directory for detailed documentation:
Examples
- 17Track API Client — Full example of integrating with the 17track shipping API.
Testing
composer test
Static Analysis
composer analyse
License
MIT License. See LICENSE for details.