Skip to content

Commit

Permalink
Fix CoreExtension::captureOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Aug 27, 2024
1 parent f9f7b79 commit 7ba6866
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1888,30 +1888,22 @@ public static function checkArrowInSandbox(Environment $env, $arrow, $thing, $ty
*/
public static function captureOutput(iterable $body): string
{
$output = '';
$level = ob_get_level();
ob_start();

try {
foreach ($body as $data) {
if (ob_get_length()) {
$output .= ob_get_clean();
ob_start();
}

$output .= $data;
}

if (ob_get_length()) {
$output .= ob_get_clean();
echo $data;
}
} finally {
} catch (\Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}

throw $e;
}

return $output;
return ob_get_clean();
}

/**
Expand Down

0 comments on commit 7ba6866

Please sign in to comment.