Skip to content

Commit c84c6b5

Browse files
authored
Merge pull request #9 from PivotPHP/6-diferenças-de-tipos-requestresponse
6 diferenças de tipos request response
2 parents 7311050 + 3538515 commit c84c6b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+14444
-600
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,4 @@ TODO.md
259259
NOTES.md
260260
scratch/
261261
benchmarks/**/*.json
262+
CLAUDE.md

CHANGELOG.md

Lines changed: 143 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,147 @@ All notable changes to the PivotPHP Framework will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.0] - 2025-07-09
9+
10+
### 🚀 **High-Performance Edition**
11+
12+
> 📖 **Complete documentation:** [docs/releases/v1.1.0/](docs/releases/v1.1.0/)
13+
14+
#### Added
15+
- **High-Performance Mode**: Centralized performance management with pre-configured profiles
16+
- `STANDARD` profile for applications <1K req/s
17+
- `HIGH` profile for 1K-10K req/s
18+
- `EXTREME` profile for >10K req/s
19+
- Easy one-line enablement: `HighPerformanceMode::enable(HighPerformanceMode::PROFILE_HIGH)`
20+
- **Dynamic Object Pooling**: Auto-scaling pools with intelligent overflow handling
21+
- `DynamicPool` with automatic expansion/shrinking based on load
22+
- Four overflow strategies: ElasticExpansion, PriorityQueuing, GracefulFallback, SmartRecycling
23+
- Emergency mode for extreme load conditions
24+
- Pool metrics and efficiency tracking
25+
- **Performance Middleware Suite**:
26+
- `LoadShedder`: Intelligent request dropping under overload (priority, random, oldest, adaptive strategies)
27+
- `CircuitBreaker`: Failure isolation with automatic recovery (CLOSED, OPEN, HALF_OPEN states)
28+
- Enhanced `RateLimiter` with burst support and priority handling
29+
- **Memory Management System**:
30+
- `MemoryManager` with adaptive GC strategies
31+
- Automatic pool size adjustments based on memory pressure
32+
- Four pressure levels: LOW, MEDIUM, HIGH, CRITICAL
33+
- Emergency mode activation under critical conditions
34+
- **Distributed Pool Coordination** (Extension-based):
35+
- `DistributedPoolManager` for multi-instance deployments
36+
- Built-in `NoOpCoordinator` for single-instance operation
37+
- Redis/etcd/Consul support via optional extensions
38+
- Leader election for pool rebalancing
39+
- Cross-instance object sharing
40+
- **Real-Time Performance Monitoring**:
41+
- `PerformanceMonitor` with live metrics collection
42+
- Latency percentiles (P50, P90, P95, P99)
43+
- Throughput and error rate tracking
44+
- Prometheus-compatible metric export
45+
- Built-in alerting system
46+
- **Console Commands**:
47+
- `pool:stats` for real-time pool monitoring
48+
- Performance metrics display
49+
- Health status monitoring
50+
51+
#### Performance Improvements
52+
- **25x faster** Request/Response creation (2K → 50K ops/s)
53+
- **90% reduction** in memory usage per request (100KB → 10KB)
54+
- **90% reduction** in P99 latency (50ms → 5ms)
55+
- **10x increase** in max throughput (5K → 50K req/s)
56+
- **Zero downtime** during pool scaling operations
57+
58+
#### Documentation
59+
- **HIGH_PERFORMANCE_GUIDE.md**: Complete usage guide with examples
60+
- **ARCHITECTURE.md**: Technical architecture and component design
61+
- **PERFORMANCE_TUNING.md**: Production tuning for maximum performance
62+
- **MONITORING.md**: Monitoring setup with Prometheus/Grafana
63+
64+
## [1.0.1] - 2025-07-09
65+
66+
### 🔄 **PSR-7 Hybrid Support & Performance Optimizations**
67+
68+
> 📖 **See complete overview:** [docs/technical/http/](docs/technical/http/)
69+
70+
#### Added
71+
- **PSR-7 Hybrid Implementation**: Request/Response classes now implement PSR-7 interfaces while maintaining Express.js API
72+
- `Request` implements `ServerRequestInterface` with full PSR-7 compatibility
73+
- `Response` implements `ResponseInterface` with full PSR-7 compatibility
74+
- 100% backward compatibility - existing code works without changes
75+
- Lazy loading for PSR-7 objects - created only when needed
76+
- Support for PSR-15 middleware with type hints
77+
- **Object Pooling System**: Advanced memory optimization for high-performance scenarios
78+
- `Psr7Pool` class managing pools for ServerRequest, Response, Uri, and Stream objects
79+
- `OptimizedHttpFactory` with configurable pooling settings
80+
- Automatic object reuse to reduce garbage collection pressure
81+
- Configurable pool sizes and warm-up capabilities
82+
- Performance metrics and monitoring tools
83+
- **Debug Mode Documentation**: Comprehensive guide for debugging applications
84+
- Environment configuration options
85+
- Logging and error handling best practices
86+
- Security considerations for debug mode
87+
- Performance impact analysis
88+
- **Enhanced Documentation**: Complete PSR-7 hybrid usage guides
89+
- Updated Request/Response documentation with PSR-7 examples
90+
- Object pooling configuration and usage examples
91+
- Performance optimization techniques
92+
93+
#### Changed
94+
- **Request Class**: Now extends PSR-7 ServerRequestInterface while maintaining Express.js methods
95+
- `getBody()` method renamed to `getBodyAsStdClass()` for legacy compatibility
96+
- Added PSR-7 methods: `getMethod()`, `getUri()`, `getHeaders()`, `getBody()`, etc.
97+
- `getHeaders()` renamed to `getHeadersObject()` for Express.js style (returns HeaderRequest)
98+
- Immutable `with*()` methods for PSR-7 compliance
99+
- Lazy loading implementation for performance
100+
- **Distributed Pooling**: Now requires external extensions for coordination backends
101+
- Redis support moved to `pivotphp/redis-pool` extension
102+
- Built-in `NoOpCoordinator` for single-instance deployments
103+
- Automatic fallback when extensions are not available
104+
- **Response Class**: Now extends PSR-7 ResponseInterface while maintaining Express.js methods
105+
- Added PSR-7 methods: `getStatusCode()`, `getHeaders()`, `getBody()`, etc.
106+
- Immutable `with*()` methods for PSR-7 compliance
107+
- Lazy loading implementation for performance
108+
- **Factory System**: Enhanced with pooling capabilities
109+
- `OptimizedHttpFactory` replaces basic HTTP object creation
110+
- Configurable pooling for better memory management
111+
- Automatic object lifecycle management
112+
113+
#### Fixed
114+
- **Type Safety**: Resolved PHPStan Level 9 issues with PSR-7 implementation
115+
- **Method Conflicts**: Fixed `getBody()` method conflict between legacy and PSR-7 interfaces
116+
- **File Handling**: Improved file upload handling with proper PSR-7 stream integration
117+
- **Immutability**: Ensured proper immutability in PSR-7 `with*()` methods
118+
- **Test Compatibility**: Updated test suite to work with hybrid implementation
119+
120+
#### Performance Improvements
121+
- **Lazy Loading**: PSR-7 objects created only when accessed, reducing memory usage
122+
- **Object Pooling**: Significant reduction in object creation and garbage collection
123+
- **Optimized Factory**: Intelligent object reuse for better performance
124+
- **Memory Efficiency**: Up to 60% reduction in memory usage for high-traffic scenarios
125+
126+
#### Examples
127+
```php
128+
// Express.js API (unchanged)
129+
$app->get('/users/:id', function($req, $res) {
130+
$id = $req->param('id');
131+
return $res->json(['user' => $userService->find($id)]);
132+
});
133+
134+
// PSR-7 API (now supported)
135+
$app->use(function(ServerRequestInterface $request, ResponseInterface $response, $next) {
136+
$method = $request->getMethod();
137+
$newRequest = $request->withAttribute('processed', true);
138+
return $next($newRequest, $response);
139+
});
140+
141+
// Object pooling configuration
142+
OptimizedHttpFactory::initialize([
143+
'enable_pooling' => true,
144+
'warm_up_pools' => true,
145+
'max_pool_size' => 100,
146+
]);
147+
```
148+
8149
## [1.0.1] - 2025-07-08
9150

10151
### 🆕 **Regex Route Validation Support & PSR-7 Compatibility**
@@ -142,6 +283,6 @@ For questions, issues, or contributions:
142283
---
143284

144285
**Current Version**: v1.0.1
145-
**Release Date**: July 8, 2025
146-
**Status**: Ideal for concept validation and studies
286+
**Release Date**: July 9, 2025
287+
**Status**: Production-ready with PSR-7 hybrid support
147288
**Minimum PHP**: 8.1

CLAUDE.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Repository Overview
6+
7+
PivotPHP Core is a high-performance PHP microframework inspired by Express.js, designed for building APIs and web applications. Current version: 1.1.0 (High-Performance Edition).
8+
9+
## Essential Commands
10+
11+
### Development Workflow
12+
```bash
13+
# Run comprehensive validation (includes all checks)
14+
./scripts/validate_all.sh
15+
16+
# Quality checks
17+
composer quality:check # Run all quality checks
18+
composer phpstan # Static analysis (Level 9)
19+
composer cs:check # PSR-12 code style check
20+
composer cs:fix # Auto-fix code style issues
21+
composer audit # Check for security vulnerabilities
22+
23+
# Testing
24+
composer test # Run all tests
25+
composer test:security # Security-specific tests
26+
composer test:auth # Authentication tests
27+
composer benchmark # Performance benchmarks
28+
29+
# Run a single test file
30+
vendor/bin/phpunit tests/Core/ApplicationTest.php
31+
32+
# Run tests with specific group
33+
vendor/bin/phpunit --group stress
34+
vendor/bin/phpunit --exclude-group stress,integration
35+
36+
# Pre-commit and release
37+
./scripts/pre-commit # Run pre-commit validations
38+
./scripts/prepare_release.sh 1.1.0 # Prepare release for version 1.1.0
39+
./scripts/release.sh # Create release after preparation
40+
```
41+
42+
### Running Examples
43+
```bash
44+
composer examples:basic # Basic framework usage
45+
composer examples:auth # Authentication example
46+
composer examples:middleware # Middleware example
47+
```
48+
49+
### v1.1.0 High-Performance Features
50+
```php
51+
// Enable high-performance mode
52+
use PivotPHP\Core\Performance\HighPerformanceMode;
53+
HighPerformanceMode::enable(HighPerformanceMode::PROFILE_HIGH);
54+
55+
// Console commands for monitoring
56+
php bin/console pool:stats # Real-time pool monitoring
57+
```
58+
59+
## Code Architecture
60+
61+
### Core Framework Structure
62+
- **Service Provider Pattern**: All major components are registered via service providers in `src/Providers/`
63+
- **PSR Standards**: Strict PSR-7 (HTTP messages), PSR-15 (middleware), PSR-12 (coding style) compliance
64+
- **Container**: Dependency injection container at the heart of the framework (`src/Core/Container.php`)
65+
- **Event-Driven**: Event dispatcher with hooks system for extensibility
66+
67+
### Key Components
68+
1. **Application Core** (`src/Core/Application.php`): Main application class that bootstraps the framework
69+
- Version constant: `Application::VERSION`
70+
- Middleware aliases mapping for v1.1.0 features
71+
72+
2. **Router** (`src/Routing/Router.php`): High-performance routing with middleware support
73+
- Supports regex constraints: `/users/:id<\d+>`
74+
- Predefined shortcuts: `slug`, `uuid`, `date`, etc.
75+
76+
3. **Middleware Pipeline** (`src/Middleware/`): PSR-15 compliant middleware system
77+
- v1.1.0 additions: LoadShedder, CircuitBreaker
78+
79+
4. **HTTP Layer** (`src/Http/`): PSR-7 hybrid implementation
80+
- Express.js style API with PSR-7 compliance
81+
- Object pooling via `Psr7Pool` and `OptimizedHttpFactory`
82+
83+
5. **v1.1.0 Performance Components**:
84+
- `DynamicPool`: Auto-scaling object pools
85+
- `MemoryManager`: Adaptive memory management
86+
- `PerformanceMonitor`: Real-time metrics
87+
- `DistributedPoolManager`: Multi-instance coordination
88+
89+
### Request/Response Hybrid Design
90+
The framework uses a hybrid approach for PSR-7 compatibility:
91+
- `Request` class implements `ServerRequestInterface` while maintaining Express.js methods
92+
- Legacy `getBody()` renamed to `getBodyAsStdClass()` for backward compatibility
93+
- PSR-7 objects are lazy-loaded for performance
94+
95+
### Testing Approach
96+
- Tests organized by domain in `tests/` directory
97+
- Each major component has its own test suite
98+
- Integration tests verify component interaction
99+
- Use PHPUnit assertions and follow existing test patterns
100+
- v1.1.0 tests in `tests/Integration/V11ComponentsTest.php` and `tests/Stress/`
101+
102+
### Code Style Requirements
103+
- PHP 8.1+ features are used throughout
104+
- Strict typing is enforced
105+
- PHPStan Level 9 must pass
106+
- PSR-12 coding standard via PHP_CodeSniffer
107+
- All new code must include proper type declarations
108+
109+
### Performance Considerations
110+
- Framework optimized for high throughput (2.57M ops/sec for CORS)
111+
- v1.1.0 achieves 25x faster Request/Response creation with pooling
112+
- Benchmark any performance-critical changes using `composer benchmark`
113+
- Avoid unnecessary object creation in hot paths
114+
- Use lazy loading for optional dependencies
115+
116+
## Development Workflow
117+
118+
1. Before committing, run `./scripts/pre-commit` or `./scripts/validate_all.sh`
119+
2. All tests must pass before pushing changes
120+
3. Static analysis must pass at Level 9
121+
4. Code style must comply with PSR-12
122+
5. For releases, use `./scripts/prepare_release.sh` followed by `./scripts/release.sh`
123+
124+
## Current Version Status
125+
126+
- **Current Version**: 1.1.0 (High-Performance Edition)
127+
- **Previous Stable**: 1.0.1 (PSR-7 Hybrid Support)
128+
- **Tests Status**: 315/332 passing (95% success rate)
129+
- **New Features**: High-performance mode, dynamic pooling, circuit breaker, load shedding
130+
131+
## Important Notes
132+
133+
- The framework prioritizes performance, security, and developer experience
134+
- All HTTP components are PSR-7/PSR-15 compliant
135+
- Service providers are the primary extension mechanism
136+
- The event system allows for deep customization without modifying core code
137+
- Documentation updates should be made in the `/docs` directory when adding features
138+
- v1.1.0 features are opt-in and don't affect default behavior

0 commit comments

Comments
 (0)