1 <?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
3 * Output buffering wrapper
7 namespace PMA\libraries
;
10 * Output buffering wrapper class
16 private static $_instance;
24 private function __construct()
26 $this->_mode
= $this->_getMode();
31 * This function could be used eventually to support more modes.
33 * @return integer the output buffer mode
35 private function _getMode()
38 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
39 if (ini_get('output_handler') == 'ob_gzhandler') {
40 // If a user sets the output_handler in php.ini to ob_gzhandler, then
41 // any right frame file in phpMyAdmin will not be handled properly by
42 // the browser. My fix was to check the ini file within the
43 // PMA_outBufferModeGet() function.
45 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
46 // happens when php.ini's output_buffering is not Off
53 // Zero (0) is no mode or in other words output buffering is OFF.
54 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
55 // Useful if we ever decide to combine modes. Then a bitmask field of
56 // the sum of all modes will be the natural choice.
61 * Returns the singleton OutputBuffering object
63 * @return OutputBuffering object
65 public static function getInstance()
67 if (empty(self
::$_instance)) {
68 self
::$_instance = new OutputBuffering();
70 return self
::$_instance;
74 * This function will need to run at the top of all pages if output
75 * output buffering is turned on. It also needs to be passed $mode from
76 * the PMA_outBufferModeGet() function or it will be useless.
80 public function start()
83 if ($this->_mode
&& function_exists('ob_gzhandler')) {
84 ob_start('ob_gzhandler');
87 if (! defined('TESTSUITE')) {
88 header('X-ob_mode: ' . $this->_mode
);
90 register_shutdown_function(
91 array('PMA\libraries\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 = 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
) {