2011-12-28 19:33:41 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Output extends miniMVC {
|
|
|
|
|
2011-12-29 10:31:04 -05:00
|
|
|
private $buffer, $headers;
|
|
|
|
|
2011-12-28 19:33:41 -05:00
|
|
|
function __construct()
|
|
|
|
{
|
2012-01-08 16:07:54 -05:00
|
|
|
// Compression is good!
|
|
|
|
ob_start("ob_gzhandler");
|
|
|
|
|
2011-12-28 19:33:41 -05:00
|
|
|
$this->buffer = "";
|
|
|
|
$this->headers = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP magic method called when ending the script
|
|
|
|
* Used for outputing HTML
|
|
|
|
*/
|
|
|
|
function __destruct()
|
|
|
|
{
|
|
|
|
if( ! empty($this->headers))
|
|
|
|
{
|
|
|
|
// Set headers
|
|
|
|
foreach($this->headers as $key => $val)
|
|
|
|
{
|
|
|
|
if( ! isset($val))
|
|
|
|
{
|
|
|
|
@header($key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@header("$key: $val");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! empty($this->buffer))
|
|
|
|
{
|
|
|
|
echo $this->buffer;
|
2011-12-29 10:31:04 -05:00
|
|
|
ob_end_flush();
|
2011-12-28 19:33:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a header for later output
|
|
|
|
* @param string $key
|
|
|
|
* @param string $val
|
|
|
|
*/
|
|
|
|
function set_header($key, $val)
|
|
|
|
{
|
|
|
|
$this->headers[$key] = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds text to the output buffer
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
*/
|
|
|
|
function append_output($string)
|
|
|
|
{
|
|
|
|
$this->buffer .= $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the output buffer
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
*/
|
|
|
|
function set_output($string)
|
|
|
|
{
|
|
|
|
$this->buffer = $string;
|
|
|
|
}
|
2012-01-08 16:07:54 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends headers and then removes them
|
|
|
|
*/
|
|
|
|
function flush_headers()
|
|
|
|
{
|
|
|
|
// Set headers
|
|
|
|
foreach($this->headers as $key => $val)
|
|
|
|
{
|
|
|
|
if( ! isset($val))
|
|
|
|
{
|
|
|
|
@header($key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@header("$key: $val");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty headers
|
|
|
|
$this->headers = array();
|
|
|
|
}
|
2011-12-28 19:33:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of Output.php
|