Skip to content

Commit

Permalink
bug #4242 Fix CoreExtension::captureOutput (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Fix CoreExtension::captureOutput

Fix #4146

I forgot these lines in #4216

Commits
-------

7ba6866 Fix CoreExtension::captureOutput
  • Loading branch information
fabpot committed Aug 27, 2024
2 parents f9f7b79 + 7ba6866 commit f9b7e81
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 f9b7e81

Please sign in to comment.