Symfony\Component\HttpFoundation\Response::closeOutputBuffers PHP Method

closeOutputBuffers() public static method

Resulting level can be greater than target level if a non-removable buffer has been encountered.
public static closeOutputBuffers ( integer $targetLevel, boolean $flush )
$targetLevel integer The target output buffering level
$flush boolean Whether to flush or clean the buffers
    public static function closeOutputBuffers($targetLevel, $flush)
    {
        $status = ob_get_status(true);
        $level = count($status);
        // PHP_OUTPUT_HANDLER_* are not defined on HHVM 3.3
        $flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1;

        while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) {
            if ($flush) {
                ob_end_flush();
            } else {
                ob_end_clean();
            }
        }
    }

Usage Example

 /**
  * @param int     $startObLevel
  *
  * @return string
  */
 protected function getAndCleanOutputBuffering($startObLevel)
 {
     if (ob_get_level() <= $startObLevel) {
         return '';
     }
     Response::closeOutputBuffers($startObLevel + 1, true);
     return ob_get_clean();
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Response::closeOutputBuffers