1 <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
3 * Output buffering wrapper
7 if (! defined('PHPMYADMIN')) {
12 * Output buffering wrapper class
16 class PMA_OutputBuffering
18 private static $_instance;
26 private function __construct()
28 $this->_mode
= $this->_getMode();
33 * This function could be used eventually to support more modes.
35 * @return integer the output buffer mode
37 private function _getMode()
40 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
41 if (ini_get('output_handler') == 'ob_gzhandler') {
42 // If a user sets the output_handler in php.ini to ob_gzhandler, then
43 // any right frame file in phpMyAdmin will not be handled properly by
44 // the browser. My fix was to check the ini file within the
45 // PMA_outBufferModeGet() function.
47 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
48 // happens when php.ini's output_buffering is not Off
55 // Zero (0) is no mode or in other words output buffering is OFF.
56 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
57 // Useful if we ever decide to combine modes. Then a bitmask field of
58 // the sum of all modes will be the natural choice.
63 * Returns the singleton PMA_OutputBuffering object
65 * @return PMA_OutputBuffering object
67 public static function getInstance()
69 if (empty(self
::$_instance)) {
70 self
::$_instance = new PMA_OutputBuffering();
72 return self
::$_instance;
76 * This function will need to run at the top of all pages if output
77 * output buffering is turned on. It also needs to be passed $mode from
78 * the PMA_outBufferModeGet() function or it will be useless.
82 public function start()
85 if ($this->_mode
&& function_exists('ob_gzhandler')) {
86 ob_start('ob_gzhandler');
89 if (! defined('TESTSUITE')) {
90 header('X-ob_mode: ' . $this->_mode
);
92 register_shutdown_function('PMA_OutputBuffering::stop');
98 * This function will need to run at the bottom of all pages if output
99 * buffering is turned on. It also needs to be passed $mode from the
100 * PMA_outBufferModeGet() function or it will be useless.
104 public static function stop()
106 $buffer = PMA_OutputBuffering
::getInstance();
108 $buffer->_on
= false;
109 $buffer->_content
= ob_get_contents();
115 * Gets buffer content
117 * @return string buffer content
119 public function getContents()
121 return $this->_content
;
125 * Flushes output buffer
129 public function flush()
131 if (ob_get_status() && $this->_mode
) {