From 18658da099a5e96c0ac131411ba47763f1988656 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 12 Jul 2024 16:34:50 +0300 Subject: [PATCH] Add ability to change the size of the buffer to send the content of the message body (#80) --- CHANGELOG.md | 1 + README.md | 12 ++++++++++++ src/HttpApplicationRunner.php | 11 ++++++++--- src/SapiEmitter.php | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 595c0a1..b323abb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 3.0.0 under development +- New #80: Add ability to change the size of the buffer to send the content of the message body (@vjik) - Chg #76: Allow to use any PSR logger, `NullLogger` by default (@vjik) - Chg #77: Remove `ServerRequestFactory` (@vjik) - Chg #77: Mark `SapiEmitter` as internal (@vjik) diff --git a/README.md b/README.md index 108078e..3c21f33 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,18 @@ recursive merge parameters. `$nestedEventsGroups` — configuration group names that are included into events' configuration group. This is needed for reverse and recursive merge events' configurations. +`$configModifiers` — [configuration modifiers](https://github.com/yiisoft/config#configuration-modifiers). + +`$configDirectory` — the relative path from `$rootPath` to the configuration storage location. + +`$vendorDirectory` — the relative path from `$rootPath` to the vendor directory. + +`$configMergePlanFile` — the relative path from `$configDirectory` to merge plan. + +`$logger` — the logger to collect errors while container is building. + +`$bufferSize` — the size of the buffer in bytes to send the content of the message body (default, 8Mb). + #### Immutable setters If the configuration instance settings differ from the default you can specify a customized configuration instance: diff --git a/src/HttpApplicationRunner.php b/src/HttpApplicationRunner.php index df4e196..682f678 100644 --- a/src/HttpApplicationRunner.php +++ b/src/HttpApplicationRunner.php @@ -54,6 +54,8 @@ final class HttpApplicationRunner extends ApplicationRunner * @param string $configDirectory The relative path from {@see $rootPath} to the configuration storage location. * @param string $vendorDirectory The relative path from {@see $rootPath} to the vendor directory. * @param string $configMergePlanFile The relative path from {@see $configDirectory} to merge plan. + * @param LoggerInterface|null $logger The logger to collect errors while container is building. + * @param int|null $bufferSize The size of the buffer in bytes to send the content of the message body. * * @psalm-param list $nestedParamsGroups * @psalm-param list $nestedEventsGroups @@ -78,6 +80,7 @@ public function __construct( string $vendorDirectory = 'vendor', string $configMergePlanFile = '.merge-plan.php', private ?LoggerInterface $logger = null, + private ?int $bufferSize = null, ) { parent::__construct( $rootPath, @@ -131,8 +134,10 @@ public function run(): void $container = $this->getContainer(); - // Register error handler with real container-configured dependencies. - /** @var ErrorHandler $actualErrorHandler */ + /** + * Register error handler with real container-configured dependencies. + * @var ErrorHandler $actualErrorHandler + */ $actualErrorHandler = $container->get(ErrorHandler::class); $this->registerErrorHandler($actualErrorHandler, $temporaryErrorHandler); @@ -186,7 +191,7 @@ private function createTemporaryErrorHandler(): ErrorHandler */ private function emit(ServerRequestInterface $request, ResponseInterface $response): void { - (new SapiEmitter())->emit($response, $request->getMethod() === Method::HEAD); + (new SapiEmitter($this->bufferSize))->emit($response, $request->getMethod() === Method::HEAD); } /** diff --git a/src/SapiEmitter.php b/src/SapiEmitter.php index 439797b..cf249d0 100644 --- a/src/SapiEmitter.php +++ b/src/SapiEmitter.php @@ -37,7 +37,7 @@ final class SapiEmitter /** * @param int|null $bufferSize The size of the buffer in bytes to send the content of the message body. */ - public function __construct(int $bufferSize = null) + public function __construct(?int $bufferSize = null) { if ($bufferSize !== null && $bufferSize < 1) { throw new InvalidArgumentException('Buffer size must be greater than zero.');