123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace PhpMyAdmin;
- class OutputBuffering
- {
- private static $_instance;
- private $_mode;
- private $_content;
- private $_on;
-
- private function __construct()
- {
- $this->_mode = $this->_getMode();
- $this->_on = false;
- }
-
- private function _getMode()
- {
- $mode = 0;
- if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
- if (ini_get('output_handler') == 'ob_gzhandler') {
-
-
-
-
- $mode = 0;
- } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
-
- ob_end_clean();
- $mode = 1;
- } else {
- $mode = 1;
- }
- }
-
-
-
-
- return $mode;
- }
-
- public static function getInstance()
- {
- if (empty(self::$_instance)) {
- self::$_instance = new OutputBuffering();
- }
- return self::$_instance;
- }
-
- public function start()
- {
- if (! $this->_on) {
- if ($this->_mode && function_exists('ob_gzhandler')) {
- ob_start('ob_gzhandler');
- }
- ob_start();
- if (! defined('TESTSUITE')) {
- header('X-ob_mode: ' . $this->_mode);
- }
- register_shutdown_function(
- array(OutputBuffering::class, 'stop')
- );
- $this->_on = true;
- }
- }
-
- public static function stop()
- {
- $buffer = OutputBuffering::getInstance();
- if ($buffer->_on) {
- $buffer->_on = false;
- $buffer->_content = ob_get_contents();
- if (ob_get_length() > 0) {
- ob_end_clean();
- }
- }
- }
-
- public function getContents()
- {
- return $this->_content;
- }
-
- public function flush()
- {
- if (ob_get_status() && $this->_mode) {
- ob_flush();
- } else {
- flush();
- }
- }
- }
|