@@ -28,18 +28,43 @@ $response->json($data); // Now uses pooling when beneficial
2828```
2929
3030** Smart Detection Criteria:**
31- - Arrays with 10+ elements
32- - Objects with 5+ properties
33- - Strings larger than 1KB
31+ - Arrays with 10+ elements (JsonBufferPool::POOLING_ARRAY_THRESHOLD)
32+ - Objects with 5+ properties (JsonBufferPool::POOLING_OBJECT_THRESHOLD)
33+ - Strings larger than 1KB (JsonBufferPool::POOLING_STRING_THRESHOLD)
3434
35- ### Manual Pool Control
35+ ### Enhanced Error Handling & Type Safety
36+
37+ ** Precise Validation Messages:**
38+ ``` php
39+ // Type errors are clearly separated from range errors
40+ try {
41+ JsonBufferPool::configure(['max_pool_size' => 'invalid']);
42+ } catch (InvalidArgumentException $e) {
43+ echo $e->getMessage(); // "'max_pool_size' must be an integer"
44+ }
45+
46+ try {
47+ JsonBufferPool::configure(['max_pool_size' => -1]);
48+ } catch (InvalidArgumentException $e) {
49+ echo $e->getMessage(); // "'max_pool_size' must be a positive integer"
50+ }
51+ ```
52+
53+ ** Always-String Return Type:**
54+ ``` php
55+ // encodeWithPool() now always returns string, never false
56+ $json = JsonBufferPool::encodeWithPool($data); // Always string
57+ // No need to check for false - error handling is internal
58+ ```
59+
60+ ### Manual Pool Control & Public Constants
3661
3762For advanced use cases, direct pool access is available:
3863
3964``` php
4065use PivotPHP\Core\Json\Pool\JsonBufferPool;
4166
42- // Direct encoding with pooling
67+ // Direct encoding with pooling (always returns string)
4368$json = JsonBufferPool::encodeWithPool($data);
4469
4570// Manual buffer management
@@ -49,6 +74,27 @@ $result = $buffer->finalize();
4974JsonBufferPool::returnBuffer($buffer);
5075```
5176
77+ ** Public Constants for Advanced Usage:**
78+ ``` php
79+ // Size estimation constants
80+ JsonBufferPool::EMPTY_ARRAY_SIZE; // 2
81+ JsonBufferPool::SMALL_ARRAY_SIZE; // 512
82+ JsonBufferPool::MEDIUM_ARRAY_SIZE; // 2048
83+ JsonBufferPool::LARGE_ARRAY_SIZE; // 8192
84+ JsonBufferPool::XLARGE_ARRAY_SIZE; // 32768
85+
86+ // Pooling thresholds
87+ JsonBufferPool::POOLING_ARRAY_THRESHOLD; // 10
88+ JsonBufferPool::POOLING_OBJECT_THRESHOLD; // 5
89+ JsonBufferPool::POOLING_STRING_THRESHOLD; // 1024
90+
91+ // Type-specific constants
92+ JsonBufferPool::STRING_OVERHEAD; // 20
93+ JsonBufferPool::OBJECT_PROPERTY_OVERHEAD; // 50
94+ JsonBufferPool::OBJECT_BASE_SIZE; // 100
95+ JsonBufferPool::MIN_LARGE_BUFFER_SIZE; // 65536
96+ ```
97+
5298### Real-time Monitoring
5399
54100Comprehensive statistics for production monitoring:
@@ -180,17 +226,20 @@ For maximum performance, consider these enhancements:
180226
181227### Test Coverage
182228
183- - ** 20 new tests** covering all JSON pooling functionality
184- - ** 60 additional assertions** validating behavior
229+ - ** 84 JSON tests** covering all pooling functionality
230+ - ** 329+ total assertions** validating behavior
185231- ** All existing tests** continue to pass (335+ tests total)
186232- ** PSR-12 compliance** maintained throughout
233+ - ** Enhanced test maintainability** with constant-based assertions
187234
188235### Validation
189236
190237- ** Memory leak testing** - No buffer leaks detected
191238- ** Stress testing** - 60+ seconds sustained load
192239- ** Compatibility testing** - All existing functionality preserved
193240- ** Performance regression testing** - No slowdowns for any use case
241+ - ** Type safety validation** - Precise error message testing
242+ - ** Configuration validation** - Comprehensive parameter checking
194243
195244## 🎯 Use Cases
196245
0 commit comments