merged branch lencioni/fix-clean-output-buffering (PR #3667)
Commits
-------
068e859
[TwigBundle] Changed getAndCleanOutputBuffering() handling of systems where ob_get_level() never returns 0
Discussion
----------
[TwigBundle] Changed getAndCleanOutputBuffering() handling of systems where ob_get_level() never returns 0
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/lencioni/symfony.png)](http://travis-ci.org/lencioni/symfony)
Fixes the following tickets: -
Todo: -
Relying on decrementing a counter has two problems. First, and most importantly, if the output buffering nesting level is greater than the counter, the function does not perform the expected task. Secondly, on systems where the counter is needed, a lot of unnecessary extra loops would potentially occur.
This approach checks to see if the level has stayed the same from the previous iteration and if it has it stops looping.
---------------------------------------------------------------------------
by fabpot at 2012-03-21T21:29:50Z
Have you encounter this problem to confirm that your approach works?
---------------------------------------------------------------------------
by vicb at 2012-03-21T21:35:39Z
@lencioni could you also provide an answer from my question in the former version of this PR ?
---------------------------------------------------------------------------
by lencioni at 2012-03-21T21:56:06Z
@fabpot I have not encountered this problem personally, but the code I submitted is [similar to an approach I use in SLIR](https://github.com/lencioni/SLIR/blob/master/core/slir.class.php#L462), which has been successful for people who have encountered it.
@vicb You are referring to [this question](https://github.com/symfony/symfony/pull/3666#issuecomment-4626105), right?
>It was possible than the body of the while loop was never executed before, it is no more. Is this expected ?
I think you may have misinterpreted the change I submitted. In the original code, there were two conditions being checked in the while loop. The first condition has not changed in my code and could still prevent the body of the while loop from being never executed. The second condition in the original code would always evaluate to 99 on the first iteration, which would not prevent the loop from running.
---------------------------------------------------------------------------
by vicb at 2012-03-21T22:00:01Z
oops my mistake, sorry.
This commit is contained in:
commit
c761d0cebb
@ -61,13 +61,15 @@ class ExceptionController extends ContainerAware
|
|||||||
|
|
||||||
protected function getAndCleanOutputBuffering()
|
protected function getAndCleanOutputBuffering()
|
||||||
{
|
{
|
||||||
// the count variable avoids an infinite loop on
|
// ob_get_level() never returns 0 on some Windows configurations, so if
|
||||||
// some Windows configurations where ob_get_level()
|
// the level is the same two times in a row, the loop should be stopped.
|
||||||
// never reaches 0
|
$previousObLevel = null;
|
||||||
$count = 100;
|
|
||||||
$startObLevel = $this->container->get('request')->headers->get('X-Php-Ob-Level', -1);
|
$startObLevel = $this->container->get('request')->headers->get('X-Php-Ob-Level', -1);
|
||||||
|
|
||||||
$currentContent = '';
|
$currentContent = '';
|
||||||
while (ob_get_level() > $startObLevel && --$count) {
|
|
||||||
|
while (($obLevel = ob_get_level()) > $startObLevel && $obLevel !== $previousObLevel) {
|
||||||
|
$previousObLevel = $obLevel;
|
||||||
$currentContent .= ob_get_clean();
|
$currentContent .= ob_get_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user