| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Http\Client\Common\Plugin; |
| 6 |
|
| 7 |
use Http\Client\Common\Plugin; |
| 8 |
use Symfony\Component\OptionsResolver\OptionsResolver; |
| 9 |
|
| 10 |
/** |
| 11 |
* @internal |
| 12 |
*/ |
| 13 |
abstract class SeekableBodyPlugin implements Plugin |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @var bool |
| 17 |
*/ |
| 18 |
protected $useFileBuffer; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var int |
| 22 |
*/ |
| 23 |
protected $memoryBufferSize; |
| 24 |
|
| 25 |
/** |
| 26 |
* @param array{'use_file_buffer'?: bool, 'memory_boffer_size'?: int} $config |
| 27 |
* |
| 28 |
* Configuration options: |
| 29 |
* - use_file_buffer: Whether this plugin should use a file as a buffer if the stream is too big, defaults to true |
| 30 |
* - memory_buffer_size: Max memory size in bytes to use for the buffer before it use a file, defaults to 2097152 (2 mb) |
| 31 |
*/ |
| 32 |
public function __construct(array $config = []) |
| 33 |
{ |
| 34 |
$resolver = new OptionsResolver(); |
| 35 |
$resolver->setDefaults([ |
| 36 |
'use_file_buffer' => true, |
| 37 |
'memory_buffer_size' => 2097152, |
| 38 |
]); |
| 39 |
$resolver->setAllowedTypes('use_file_buffer', 'bool'); |
| 40 |
$resolver->setAllowedTypes('memory_buffer_size', 'int'); |
| 41 |
|
| 42 |
$options = $resolver->resolve($config); |
| 43 |
|
| 44 |
$this->useFileBuffer = $options['use_file_buffer']; |
| 45 |
$this->memoryBufferSize = $options['memory_buffer_size']; |
| 46 |
} |
| 47 |
} |
| 48 |
|