|
| 1 | +# Performance Tools Migration Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +A partir da versão 2.2.0, os componentes de performance do PivotPHP foram migrados para um pacote separado: **`pivotphp/performance-tools`**. |
| 6 | + |
| 7 | +Esta mudança permite: |
| 8 | +- ✅ **Modularização**: Performance tools como pacote independente |
| 9 | +- ✅ **Compatibilidade BC**: Aliases automáticos até v3.0.0 |
| 10 | +- ✅ **Injeção de Dependências**: Interfaces e adapters para flexibilidade |
| 11 | +- ✅ **Manutenção**: Separação clara de responsabilidades |
| 12 | + |
| 13 | +## Migrated Components |
| 14 | + |
| 15 | +| Component | Location | New Package | |
| 16 | +|-----------|----------|-------------| |
| 17 | +| Psr7Pool | `PivotPHP\Core\Http\Pool` | `PivotPHP\PerformanceTools\Http\Psr7\Pool` | |
| 18 | +| PoolManager | `PivotPHP\Core\Http\Psr7\Pool` | `PivotPHP\PerformanceTools\Http\Psr7\Pool` | |
| 19 | +| ResponsePool | `PivotPHP\Core\Http\Psr7\Pool` | `PivotPHP\PerformanceTools\Http\Psr7\Pool` | |
| 20 | +| HeaderPool | `PivotPHP\Core\Http\Psr7\Pool` | `PivotPHP\PerformanceTools\Http\Psr7\Pool` | |
| 21 | +| EnhancedStreamPool | `PivotPHP\Core\Http\Psr7\Pool` | `PivotPHP\PerformanceTools\Http\Psr7\Pool` | |
| 22 | +| OperationsCache | `PivotPHP\Core\Http\Psr7\Cache` | `PivotPHP\PerformanceTools\Http\Psr7\Cache` | |
| 23 | +| JsonBufferPool | `PivotPHP\Core\Json\Pool` | `PivotPHP\PerformanceTools\Json\Pool` | |
| 24 | +| JsonBuffer | `PivotPHP\Core\Json\Pool` | `PivotPHP\PerformanceTools\Json\Pool` | |
| 25 | +| MiddlewarePipelineCompiler | `PivotPHP\Core\Middleware` | `PivotPHP\PerformanceTools\Middleware` | |
| 26 | +| SerializationCache | `PivotPHP\Core\Utils` | `PivotPHP\PerformanceTools\Utils` | |
| 27 | + |
| 28 | +## Backward Compatibility (v2.2.0 - v2.9.x) |
| 29 | + |
| 30 | +**No breaking changes!** O PivotPHP Core v2.2.0+ inclui aliases automáticos que redirecionam as classes antigas para o novo pacote. |
| 31 | + |
| 32 | +### Old Code (Still Works) |
| 33 | + |
| 34 | +```php |
| 35 | +use PivotPHP\Core\Http\Pool\Psr7Pool; |
| 36 | +use PivotPHP\Core\Http\Psr7\Pool\PoolManager; |
| 37 | +use PivotPHP\Core\Json\Pool\JsonBufferPool; |
| 38 | + |
| 39 | +// Funciona exatamente como antes |
| 40 | +$pool = Psr7Pool::getServerRequest(...); |
| 41 | +``` |
| 42 | + |
| 43 | +### New Code (Recommended) |
| 44 | + |
| 45 | +```php |
| 46 | +use PivotPHP\PerformanceTools\Http\Psr7\Pool\Psr7Pool; |
| 47 | +use PivotPHP\PerformanceTools\Http\Psr7\Pool\PoolManager; |
| 48 | +use PivotPHP\PerformanceTools\Json\Pool\JsonBufferPool; |
| 49 | + |
| 50 | +// Mesmo funcionamento, namespaces claros |
| 51 | +$pool = Psr7Pool::getServerRequest(...); |
| 52 | +``` |
| 53 | + |
| 54 | +## Installation |
| 55 | + |
| 56 | +### For Development/Optional Performance |
| 57 | + |
| 58 | +```bash |
| 59 | +# Install pivotphp/performance-tools if not already included |
| 60 | +composer require pivotphp/performance-tools |
| 61 | +``` |
| 62 | + |
| 63 | +### For Production |
| 64 | + |
| 65 | +O PivotPHP Core mantém cópias injetáveis das interfaces para permitir que aplicações funcionem sem o pacote performance-tools. Para máxima performance, instale o pacote: |
| 66 | + |
| 67 | +```bash |
| 68 | +composer require pivotphp/performance-tools |
| 69 | +``` |
| 70 | + |
| 71 | +## Interfaces & Adapters |
| 72 | + |
| 73 | +O Core v2.2.0 introduz interfaces e adapters para permitir injeção de dependências sem criar dependências rígidas: |
| 74 | + |
| 75 | +### Interfaces (em `src/Contracts/`) |
| 76 | + |
| 77 | +- `JsonOptimizerInterface` |
| 78 | +- `Psr7PoolInterface` |
| 79 | +- `ResponsePoolInterface` |
| 80 | +- `HeaderPoolInterface` |
| 81 | +- `StreamPoolInterface` |
| 82 | +- `OperationsCacheInterface` |
| 83 | +- `SerializationCacheInterface` |
| 84 | +- `MiddlewarePipelineCompilerInterface` |
| 85 | + |
| 86 | +### Adapters (em `src/Http/Adapters/`, `src/Json/Adapters/`, etc.) |
| 87 | + |
| 88 | +Os adapters implementam as interfaces e delegam para as classes do PerformanceTools quando disponíveis, ou caem de volta para implementações simples quando o pacote não está instalado. |
| 89 | + |
| 90 | +## Architecture Changes |
| 91 | + |
| 92 | +### Before (v2.1.x) |
| 93 | + |
| 94 | +``` |
| 95 | +Core |
| 96 | +├── Http/Pool/Psr7Pool |
| 97 | +├── Http/Psr7/Pool/PoolManager |
| 98 | +├── Json/Pool/JsonBufferPool |
| 99 | +├── Middleware/MiddlewarePipelineCompiler |
| 100 | +└── Utils/SerializationCache |
| 101 | +``` |
| 102 | + |
| 103 | +### After (v2.2.0+) |
| 104 | + |
| 105 | +``` |
| 106 | +Core |
| 107 | +├── Contracts/ (Interfaces) |
| 108 | +├── Adapters/ (Delegates to PerformanceTools) |
| 109 | +└── aliases-performance-tools.php (BC) |
| 110 | +
|
| 111 | +PerformanceTools (Separate Package) |
| 112 | +├── Http/Psr7/Pool/ (Psr7Pool, PoolManager, ResponsePool, etc.) |
| 113 | +├── Http/Psr7/Cache/ (OperationsCache) |
| 114 | +├── Json/Pool/ (JsonBufferPool, JsonBuffer) |
| 115 | +├── Middleware/ (MiddlewarePipelineCompiler) |
| 116 | +└── Utils/ (SerializationCache) |
| 117 | +``` |
| 118 | + |
| 119 | +## Dependency Injection |
| 120 | + |
| 121 | +A injeção de dependências agora funciona via interfaces e adapters: |
| 122 | + |
| 123 | +### Example: Custom Psr7Pool Implementation |
| 124 | + |
| 125 | +```php |
| 126 | +use PivotPHP\Core\Contracts\Psr7PoolInterface; |
| 127 | +use PivotPHP\Core\Http\Facades\HttpPoolFacade; |
| 128 | + |
| 129 | +class CustomPool implements Psr7PoolInterface { |
| 130 | + // Implementação customizada |
| 131 | +} |
| 132 | + |
| 133 | +// Injetar no façade |
| 134 | +HttpPoolFacade::setPool(new CustomPool()); |
| 135 | + |
| 136 | +// Ou via PoolManager |
| 137 | +PoolManager::setResponsePool(...); |
| 138 | +PoolManager::setHeaderPool(...); |
| 139 | +``` |
| 140 | + |
| 141 | +## Migration v2.x → v3.0.0 |
| 142 | + |
| 143 | +Na v3.0.0, as aliases serão removidas. Para preparar seu código: |
| 144 | + |
| 145 | +### Step 1: Update Imports |
| 146 | + |
| 147 | +```php |
| 148 | +// Old |
| 149 | +use PivotPHP\Core\Http\Pool\Psr7Pool; |
| 150 | + |
| 151 | +// New |
| 152 | +use PivotPHP\PerformanceTools\Http\Psr7\Pool\Psr7Pool; |
| 153 | +``` |
| 154 | + |
| 155 | +### Step 2: Ensure performance-tools is Installed |
| 156 | + |
| 157 | +```bash |
| 158 | +composer require pivotphp/performance-tools |
| 159 | +``` |
| 160 | + |
| 161 | +### Step 3: Test Your Application |
| 162 | + |
| 163 | +```bash |
| 164 | +composer test |
| 165 | +``` |
| 166 | + |
| 167 | +## Deprecation Timeline |
| 168 | + |
| 169 | +| Version | Status | Notes | |
| 170 | +|---------|--------|-------| |
| 171 | +| v2.1.x | ✅ Current | All in Core | |
| 172 | +| v2.2.0 - v2.9.x | ✅ Supported | Aliases available, new package recommended | |
| 173 | +| v3.0.0 | ⚠️ Upcoming | Aliases removed, performance-tools required | |
| 174 | + |
| 175 | +## Support |
| 176 | + |
| 177 | +For issues or questions about the migration: |
| 178 | + |
| 179 | +1. Check the [PerformanceTools documentation](../pivotphp-performance-tools/README.md) |
| 180 | +2. Review [Core Contracts](src/Contracts/) |
| 181 | +3. Open an issue on GitHub |
| 182 | + |
| 183 | +## See Also |
| 184 | + |
| 185 | +- [PerformanceTools README](../pivotphp-performance-tools/README.md) |
| 186 | +- [Architecture Decision Record: Performance Tools Package Separation](./docs/adr-001-performance-tools-separation.md) |
0 commit comments