2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Output buffering wrapper
8 if (! defined('PHPMYADMIN')) {
13 * Output buffering wrapper class
17 class PMA_OutputBuffering
19 private static $_instance;
29 private function __construct()
31 $this->_mode
= $this->_getMode();
36 * This function could be used eventually to support more modes.
38 * @return integer the output buffer mode
40 private function _getMode()
43 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
44 if (ini_get('output_handler') == 'ob_gzhandler') {
45 // If a user sets the output_handler in php.ini to ob_gzhandler, then
46 // any right frame file in phpMyAdmin will not be handled properly by
47 // the browser. My fix was to check the ini file within the
48 // PMA_outBufferModeGet() function.
50 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
51 // If output buffering is enabled in php.ini it's not possible to
52 // add the ob_gzhandler without a warning message from php 4.3.0.
53 // Being better safe than sorry, check for any existing output handler
54 // instead of just checking the 'output_buffering' setting.
60 // Zero (0) is no mode or in other words output buffering is OFF.
61 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
62 // Usefull if we ever decide to combine modes. Then a bitmask field of
63 // the sum of all modes will be the natural choice.
68 * Returns the singleton PMA_OutputBuffering object
70 * @return PMA_OutputBuffering object
72 public static function getInstance()
74 if (empty(self
::$_instance)) {
75 self
::$_instance = new PMA_OutputBuffering();
77 return self
::$_instance;
81 * This function will need to run at the top of all pages if output
82 * output buffering is turned on. It also needs to be passed $mode from
83 * the PMA_outBufferModeGet() function or it will be useless.
87 public function start()
91 ob_start('ob_gzhandler');
94 if (! defined('TESTSUITE')) {
95 header('X-ob_mode: ' . $this->_mode
);
97 register_shutdown_function('PMA_OutputBuffering::stop');
103 * This function will need to run at the bottom of all pages if output
104 * buffering is turned on. It also needs to be passed $mode from the
105 * PMA_outBufferModeGet() function or it will be useless.
109 public static function stop()
111 $buffer = PMA_OutputBuffering
::getInstance();
113 $buffer->_on
= false;
114 $buffer->_content
= ob_get_contents();
117 PMA_Response
::response();
121 * Gets buffer content
123 * @return buffer content
125 public function getContents()
127 return $this->_content
;
131 * Flushes output buffer
135 public function flush()
137 if (ob_get_status() && $this->_mode
) {
141 * previously we had here an "else flush()" but some PHP versions
142 * (at least PHP 5.2.11) have a bug (49816) that produces garbled