|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Language Policy |
| 6 | + |
| 7 | +**IMPORTANT:** The primary language for this codebase is English. All code, comments, documentation, commit messages, PR descriptions, and communications should be in English. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Testing |
| 12 | +```bash |
| 13 | +# Run PHPUnit tests |
| 14 | +./vendor/bin/phpunit tests/ |
| 15 | + |
| 16 | +# Run specific test file |
| 17 | +./vendor/bin/phpunit tests/ApiClientTest.php |
| 18 | + |
| 19 | +# Note: Most integration tests are skipped by default as they require valid API tokens |
| 20 | +``` |
| 21 | + |
| 22 | +### Dependencies |
| 23 | +```bash |
| 24 | +# Install Composer dependencies |
| 25 | +composer install |
| 26 | + |
| 27 | +# Install dev dependencies |
| 28 | +composer install --dev |
| 29 | +``` |
| 30 | + |
| 31 | +### Git Workflow |
| 32 | +```bash |
| 33 | +# Quick development push (defined in Makefile) |
| 34 | +make dev-push |
| 35 | +``` |
| 36 | + |
| 37 | +## Architecture Overview |
| 38 | + |
| 39 | +This is a minimal, agnostic PHP SDK for OpenAPI services with only essential HTTP primitives. The architecture follows a clean, simple design inspired by the Rust implementation found in `reference/openapi-rust-sdk/`. |
| 40 | + |
| 41 | +### Core Components |
| 42 | + |
| 43 | +- **`OauthClient`** (`src/OauthClient.php`): Handles OAuth authentication and token management |
| 44 | + - Uses Basic Auth with username/apikey for authentication |
| 45 | + - Supports both production (`oauth.openapi.it`) and test (`test.oauth.openapi.it`) environments |
| 46 | + - Methods: `getScopes()`, `createToken()`, `getTokens()`, `deleteToken()`, `getCounters()` |
| 47 | + |
| 48 | +- **`Client`** (`src/Client.php`): Agnostic HTTP client for making API calls |
| 49 | + - Uses Bearer token authentication |
| 50 | + - Supports GET, POST, PUT, DELETE, PATCH methods |
| 51 | + - Handles URL parameter encoding for GET requests |
| 52 | + - JSON payload encoding for POST/PUT/PATCH requests |
| 53 | + - 30-second timeout for all requests |
| 54 | + |
| 55 | +- **`Exception`** (`src/Exception.php`): Custom exception handling for HTTP and cURL errors |
| 56 | + |
| 57 | +- **Cache System** (`src/Cache/`): Optional caching interface with array-based implementation |
| 58 | + - `CacheInterface`: Contract for cache implementations |
| 59 | + - `ArrayCache`: In-memory cache implementation |
| 60 | + |
| 61 | +### Key Design Principles |
| 62 | + |
| 63 | +1. **Agnostic**: No API-specific classes - works with any OpenAPI service |
| 64 | +2. **Minimal**: Only core HTTP primitives, minimal dependencies (PHP 8.0+, cURL, JSON) |
| 65 | +3. **Clean Interface**: Simple method signatures following REST conventions |
| 66 | +4. **Environment Flexibility**: Built-in test/production environment switching |
| 67 | + |
| 68 | +### Examples Usage Patterns |
| 69 | + |
| 70 | +The `examples/` directory contains practical usage demonstrations: |
| 71 | +- Token generation with OAuth client |
| 72 | +- API calls with different HTTP methods |
| 73 | +- Complete workflow integration |
| 74 | + |
| 75 | +### PSR-4 Autoloading |
| 76 | + |
| 77 | +The project uses PSR-4 autoloading with `OpenApi\` namespace mapped to `src/` directory. |
| 78 | + |
| 79 | +## Requirements |
| 80 | + |
| 81 | +- PHP 8.0+ |
| 82 | +- cURL extension |
| 83 | +- JSON extension |
| 84 | +- PHPUnit 9.5+ for testing |
0 commit comments