generated from farzai/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 0
v2: Middleware Architecture and Fluent API #24
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Major architectural improvements: - Introduce middleware pipeline architecture (LoggingMiddleware, TimeoutMiddleware, RetryMiddleware) - Implement fluent RequestBuilder API for chainable request construction - Add advanced retry strategies with exponential backoff and jitter - Create comprehensive exception hierarchy (NetworkException, TimeoutException, JsonParseException, etc.) - Add immutable TransportConfig for thread-safe configuration - Implement RetryContext and RetryCondition for intelligent retry logic - Enhance ResponseInterface with json(), jsonOrNull(), and toArray() methods - Remove deprecated ClientInterface, RequestInterface, and related traits - Update to Pest v2 for testing - Comprehensive README with usage examples and architecture documentation Breaking changes: - Configuration is now immutable and set during build phase - Removed mutable setters in favor of builder pattern - Changed ClientInterface to use PSR-18 directly
- Update pestphp/pest from ^2.0 to ^2.30 to fix --prefer-lowest test failures * Resolves "Call to undefined function describe()" error * Ensures describe() function is available in all test scenarios - Migrate PHPUnit XML configuration to latest schema (10.5) * Removes deprecated schema warning * Updates to modern PHPUnit configuration format - Add .phpunit.cache to .gitignore for PHPUnit 10.5 cache directory All tests passing: 75 passed (133 assertions)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24 +/- ##
=============================================
+ Coverage 83.88% 96.74% +12.86%
- Complexity 101 270 +169
=============================================
Files 9 28 +19
Lines 242 830 +588
=============================================
+ Hits 203 803 +600
+ Misses 39 27 -12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…nability Implement comprehensive serialization layer using Strategy, Factory, and Dependency Injection patterns to improve code quality, performance, and extensibility. Key Features: - Modern PHP 8.1+ JSON error handling with JSON_THROW_ON_ERROR - Performance-optimized flags (UNESCAPED_SLASHES, UNESCAPED_UNICODE) - Protection against integer overflow (JSON_BIGINT_AS_STRING) - Configurable depth limits to prevent stack overflow - Enhanced exception hierarchy with detailed error information - 100% backward compatible with existing API New Components: - SerializerInterface: Strategy pattern for swappable serialization formats - JsonConfig: Immutable configuration object with fluent API - JsonSerializer: High-performance JSON encoder/decoder - SerializerFactory: Factory pattern for creating serializers - SerializationException: Base exception with metadata - JsonEncodeException: Encoding-specific exception with context Enhanced Existing Components: - Response: Injected serializer via dependency injection - RequestBuilder: Uses serializer for JSON encoding with error handling - JsonParseException: Extended with depth and size information - MockHttpClient: Consistent serializer usage in tests Design Patterns: - Strategy Pattern: Swappable serialization formats - Factory Pattern: Centralized serializer creation - Dependency Injection: Loose coupling, easy testing - Configuration Object: Immutable, fluent configuration - Template Method: Consistent exception hierarchy Performance Improvements: - Modern JSON flags reduce output size ~10% - Automatic integer overflow protection - Configurable depth limits prevent stack overflow - Preserved caching mechanism for repeated calls Testing: - 50 new comprehensive tests (JsonConfig, JsonSerializer, SerializerFactory) - All 125 tests passing with 100% backward compatibility - Edge cases covered: deep nesting, large integers, invalid JSON Future Extensions: - Easy to add XML, MessagePack, or other serialization formats - Custom serializers can be registered at runtime - Open/Closed principle allows extension without modification
- Implement ClientFactory with auto-detection for Symfony and Guzzle HTTP clients - Add HttpFactory for PSR-7/PSR-17 object creation - Create new exception classes: BadResponseException, ClientException, ServerException, HttpException - Refactor ResponseExceptionFactory with improved error message extraction - Update README with Quick Start guide and HTTP client selection documentation - Add examples directory with usage examples - Update composer.json to move Guzzle to dev dependencies and add symfony/http-client - Update tests to use new exception classes
- Add extensive PSR-7 Response implementation tests - Add middleware stack tests for push operations and empty stacks - Add new test files for exceptions, factory, and transport config - Apply code style improvements across example files (single quotes, parentheses removal) - Clean up trailing whitespace in ResponseExceptionFactory
- Change Response::$jsonDecoded type from ?array to mixed to properly handle non-array JSON (objects, scalars, etc.) - Add comprehensive test coverage for StreamInterface body handling - Add tests for non-array JSON responses and scalar value extraction - Add tests for Transport and TransportBuilder getters and configuration - Add tests for retry conditions and JSON config validation - Improve test coverage for edge cases in serialization and response handling
parsilver
added a commit
that referenced
this pull request
Oct 24, 2025
This commit introduces two major features for Transport PHP: ## Feature 1: Multipart/Form-Data File Upload - Add `Part` class for representing multipart form components - Add `MultipartStreamBuilder` for RFC 7578 compliant multipart streams - Add `withMultipart()`, `withFile()`, and `withMultipartBuilder()` methods to RequestBuilder - Support for mixed text fields and file uploads in single request - Automatic content-type detection based on file extensions - Custom boundaries, filenames, and content-types support - PSR-7 StreamInterface compliance for memory-efficient operations ## Feature 2: Cookie Management - Add `Cookie` class with RFC 6265 compliance - Add `CookieJar` for cookie storage with domain/path matching - Add `CookieMiddleware` for automatic cookie handling - Add `withCookies()` and `withCookieJar()` methods to TransportBuilder - Support for session and persistent cookies - Automatic cookie expiration handling - Cookie export/import for persistence - Secure/HttpOnly/SameSite attribute support - Proper domain and path matching algorithms ## Testing & Quality - Add comprehensive test suite (55+ new tests, 330 total passing) - Add practical examples (file-upload.php, cookie-session.php) - Update README with feature documentation and usage examples - PSR-12 code style compliance - Full type safety with PHP 8.1+ strict types ## Breaking Changes None - fully backward compatible with existing code. Closes #24 (if applicable)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces version 2 of the Transport library with a complete architectural redesign. The new version features a middleware pipeline architecture, fluent API for building requests, and advanced retry strategies with exponential backoff.
Key Features
✅ Middleware Architecture - Extensible plugin system for custom behavior
✅ Fluent Request Builder - Chainable API for building requests
✅ Advanced Retry Strategies
✅ Immutable Configuration - Thread-safe, predictable behavior
✅ Enhanced Exception Handling
✅ Improved Response Interface
json()method with dot notation supportjsonOrNull()for safe JSON parsingtoArray()for array conversionChanges
Added:
Modified:
Removed:
Breaking Changes
isSuccessfull()→isSuccessful())Migration Guide
Before (v1):
After (v2):
Test Plan
Stats
Documentation