nextcloud/lib/public/AppFramework/Http/StreamTraversableResponse.php
Côme Chilliet 1ab09ec753
chore: Apply new coding standard to all files
The diff can be checked using: git diff --ignore-all-space --ignore-blank-lines
To see only the changes not related to blank lines.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2026-06-01 13:46:39 +02:00

51 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\AppFramework\Http;
use OCP\AppFramework\Http;
use Override;
use Traversable;
/**
* Class StreamResponse
*
* @since 33.0.0
* @template-covariant S of Http::STATUS_*
* @template-covariant H of array<string, mixed>
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
*/
class StreamTraversableResponse extends Response implements ICallbackResponse {
/**
* @param S $status
* @param H $headers
* @since 33.0.0
*/
public function __construct(
private Traversable $generator,
int $status = Http::STATUS_OK,
array $headers = [],
) {
parent::__construct($status, $headers);
}
/**
* Streams the generator output
*
* @param IOutput $output a small wrapper that handles output
* @since 33.0.0
*/
#[Override]
public function callback(IOutput $output): void {
foreach ($this->generator as $content) {
$output->setOutput($content);
flush();
}
}
}