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;
28 private function __construct()
30 $this->_mode
= $this->_getMode();
35 * This function could be used eventually to support more modes.
37 * @return integer the output buffer mode
39 private function _getMode()
42 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
43 if (ini_get('output_handler') == 'ob_gzhandler') {
44 // If a user sets the output_handler in php.ini to ob_gzhandler, then
45 // any right frame file in phpMyAdmin will not be handled properly by
46 // the browser. My fix was to check the ini file within the
47 // PMA_outBufferModeGet() function.
49 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
50 // If output buffering is enabled in php.ini it's not possible to
51 // add the ob_gzhandler without a warning message from php 4.3.0.
52 // Being better safe than sorry, check for any existing output
53 // handler instead of just checking the 'output_buffering' setting.
59 // Zero (0) is no mode or in other words output buffering is OFF.
60 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
61 // Usefull if we ever decide to combine modes. Then a bitmask field of
62 // the sum of all modes will be the natural choice.
67 * Returns the singleton PMA_OutputBuffering object
69 * @return PMA_OutputBuffering object
71 public static function getInstance()
73 if (empty(self
::$_instance)) {
74 self
::$_instance = new PMA_OutputBuffering();
76 return self
::$_instance;
80 * This function will need to run at the top of all pages if output
81 * output buffering is turned on. It also needs to be passed $mode from
82 * the PMA_outBufferModeGet() function or it will be useless.
86 public function start()
90 ob_start('ob_gzhandler');
93 if (! defined('TESTSUITE')) {
94 header('X-ob_mode: ' . $this->_mode
);
96 register_shutdown_function('PMA_OutputBuffering::stop');
102 * This function will need to run at the bottom of all pages if output
103 * buffering is turned on. It also needs to be passed $mode from the
104 * PMA_outBufferModeGet() function or it will be useless.
108 public static function stop()
110 $buffer = PMA_OutputBuffering
::getInstance();
112 $buffer->_on
= false;
113 $buffer->_content
= ob_get_contents();
116 PMA_Response
::response();
120 * Gets buffer content
122 * @return buffer content
124 public function getContents()
126 return $this->_content
;
130 * Flushes output buffer
134 public function flush()
136 if (ob_get_status() && $this->_mode
) {