* @template-extends Response> */ 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(); } } }