-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add TurboDocx PHP SDK strong typing #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Remove email column from support table to focus on self-service channels (Documentation, Discord, GitHub Issues). Updates width to 33% for better layout with 3 columns. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add new Explore the TurboDocx Ecosystem section featuring html-to-docx, n8n-nodes-turbodocx, and TurboDocx Writer. Replaces callout with proper table format for better discoverability of related tools. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements a production-grade PHP SDK for TurboDocx that mirrors the TypeScript SDK's API surface using modern PHP 8.1+ features.
Core Features:
- 8 TurboSign methods for digital signatures
- Strong typing with PHP 8.1 enums and readonly classes
- TypeScript-equivalent type safety via PHPDoc generics
- Coordinate-based and template anchor field positioning
- Comprehensive exception hierarchy (5 custom exceptions)
- Magic byte detection for file type identification
- Guzzle HTTP client with error mapping
- PSR-4 autoloading and PSR-12 coding standards
Architecture:
- Static method API matching TypeScript SDK pattern
- Lazy initialization from environment variables
- Smart response unwrapping (extracts { data: {...} })
- Multipart form-data for file uploads
- JSON body for URL/deliverable/template inputs
Type System:
- 4 enums: SignatureFieldType, DocumentStatus, RecipientStatus, FieldPlacement
- 10 DTOs: Recipient, Field, TemplateConfig + Request/Response types
- Readonly classes for immutability
- Named parameters for builder-like API
Dependencies:
- PHP 8.1+ (enums, typed properties, readonly)
- Guzzle 7.8+ for HTTP client
- PSR standards compliance
- PHPStan level 8 for static analysis
Files Created: 34 core implementation files
Next Steps: Tests, examples, documentation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Adds complete documentation and examples for the PHP SDK: Examples (3 files): - turbosign-send-simple.php: Template anchors with direct sending - turbosign-basic.php: Review link workflow with template anchors - turbosign-advanced.php: Coordinate-based positioning, advanced field types, status polling README Features: - Installation and quick start guide - Complete API reference for all 8 methods - Field types and positioning strategies (coordinates + template anchors) - File input methods (upload, URL, deliverable ID) - Error handling with typed exceptions - Environment variable configuration - TypeScript → PHP equivalents table - Testing and development guide Documentation Structure: - Mirrors TypeScript SDK README format - PHP 8.1+ code examples with named parameters - PHPStan level 8 static analysis guidance - PSR-12 coding standards - Composer installation and testing commands Total: 4 files (3 examples + README) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Created 5 unit test files (31 tests, 82 assertions) - ExceptionTest: Tests all custom exception types - FieldTest: Tests field creation with coordinates and templates - FileTypeDetectorTest: Tests magic byte detection for PDF/DOCX/PPTX - HttpClientConfigTest: Tests configuration validation - RecipientTest: Tests recipient validation and serialization - Fixed PHP 8.1 compatibility issues: - Changed `readonly` class syntax to individual readonly properties - Renamed Exception::$code to $errorCode to avoid property conflict - Fixed PHPStan level 8 errors: - Added RequestException type checking for hasResponse() - Removed unused $orgId property - Fixed template type annotations - Added use statements for Recipient and Field in request classes - Code quality improvements: - Ran PHP-CS-Fixer (PSR-12 formatting) - Updated PHPStan configuration - All tests passing - Zero PHPStan errors Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Updated root README to include PHP SDK in available SDKs table - Added PHP to installation quick start section - Added PHP 8.1+ to requirements table - Updated PHP SDK README: - Fixed errorCode property reference in error handling section - Added quality metrics section highlighting test results - Added comprehensive testing documentation - Updated CHANGELOG.md: - Released v0.1.0 with complete feature set - Documented all features, type system, and testing metrics - Added TypeScript → PHP equivalents mapping Quality Metrics: - 31 unit tests with 82 assertions (100% passing) - PHPStan level 8 static analysis (0 errors) - PSR-12 code formatting compliance - PHP 8.1+ compatibility Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Added test-php job to ci.yml workflow: - PHP 8.1 setup with required extensions - Composer validation - Unit tests (31 tests, 82 assertions) - PHPStan level 8 static analysis - PSR-12 code style checks - Created publish-php.yml workflow: - Triggers on release tags matching php-sdk-v* - Validates package before publishing - Runs full test suite and quality checks - Packagist auto-detects new tags for publishing Workflow Features: - Uses shivammathur/setup-php@v2 for PHP environment - Validates composer.json structure - Ensures all tests pass before publishing - Zero-configuration Packagist publishing via Git tags Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3644c6d to
2888241
Compare
- Changed from coordinate-based positioning to template anchors - Added all advanced field types: signature, date, full_name, company, title, text - Demonstrates readonly fields with default values - Shows required checkbox with default checked - Includes multiline text field - Matches TypeScript SDK gold standard exactly Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed three response types that had incorrect structures:
1. VoidDocumentResponse:
- Changed from {documentId, status, voidedAt}
- To {success, message} (matches TS/Go)
- Updated void() method to manually construct response (backend returns empty data)
2. ResendEmailResponse:
- Changed from {documentId, message, resentAt}
- To {success, recipientCount} (matches TS/Go)
3. AuditTrailResponse:
- Changed from {documentId, entries}
- To {document: AuditTrailDocument, auditTrail} (matches TS/Go)
- Added new AuditTrailDocument class with {id, name} properties
These changes ensure complete parity with the TypeScript and Go SDK implementations.
Code reviewFound 2 issues:
SDK/.github/workflows/publish-php.yml Lines 8 to 11 in 78884cf
SDK/.github/workflows/publish-php.yml Lines 27 to 37 in 78884cf
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Code reviewFound 3 issues:
SDK/packages/php-sdk/src/TurboSign.php Lines 109 to 113 in 78884cf
SDK/.github/workflows/publish-php.yml Lines 8 to 11 in 78884cf
SDK/.github/workflows/publish-php.yml Lines 27 to 37 in 78884cf
🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Additional note: Code hygieneThe This follows the same pattern already established for
|
- Fix copy-paste bug where senderName was assigned senderEmail value in createSignatureReviewLink() - Add unit tests to verify senderName field handling - Fix publish workflow to use github.event.release.tag_name instead of github.ref_name - Remove --no-dev flag from composer install to include dev dependencies for tests - Add .php-cs-fixer.cache to .gitignore and remove from repository Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add proper PHPDoc annotations for array parameters and return type to satisfy PHPStan level 8 requirements. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📚 Documentation ReadyComprehensive PHP SDK documentation has been created and is ready for review! Documentation PR: TurboDocx/Docs#44 What's IncludedThe documentation PR adds:
PreviewThe docs showcase the PHP SDK's features:
Once both PRs are merged, developers will have production-ready SDK + documentation! 🚀 |
Summary
Implements a production-grade PHP SDK for TurboDocx that achieves TypeScript-equivalent strong typing using modern PHP 8.1+ features.
Key Features
Architecture Highlights
{ data: {...} })Type System
Enums (4):
SignatureFieldType- 11 field typesDocumentStatus- 6 document statesRecipientStatus- 3 recipient statesFieldPlacement- 5 template placement optionsDTOs (10):
Recipient,Field,TemplateConfigSendSignatureRequest,CreateSignatureReviewLinkRequestFiles Created
What's Remaining
Test Plan
Dependencies
{ "php": "^8.1", "guzzlehttp/guzzle": "^7.8", "psr/http-client": "^1.0", "psr/http-message": "^2.0" }Dev Dependencies: PHPUnit 10.5+, PHPStan 1.10+, PHP-CS-Fixer 3.48+
TypeScript → PHP Equivalents
type FieldType = 'signature' | 'date'enum SignatureFieldType: string { case SIGNATURE = 'signature'; }interface Recipient { name: string }final readonly class Recipient { public function __construct(public string $name) {} }request<T>(path): Promise<T>/** @template T */ public function request(string $path): mixedoptional?: stringpublic ?string $optional = nullstatic configure(config)public static function configure(HttpClientConfig $config): voidNext Steps
composer installand verify all tests pass🤖 Generated with Claude Code