Various small improvements

This commit is contained in:
Timothy Warren 2012-01-08 16:07:54 -05:00
parent 42ffdd0ad9
commit 2d85763af6
3 changed files with 66 additions and 38 deletions

View File

@ -266,6 +266,21 @@ class miniMVC extends JSObject{
unset($this->$name); unset($this->$name);
} }
} }
/**
* Convenience function to load config files
*
* @param string $name
*/
function load_config($name)
{
$path = APP_PATH . "config/{$name}.php";
if(is_file($path))
{
require_once($path);
}
}
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -1,20 +1,18 @@
<?php <?php
/**
* Class for content output
*/
class Output extends miniMVC { class Output extends miniMVC {
private $buffer, $headers; private $buffer, $headers;
function __construct() function __construct()
{ {
// Compression is good!
ob_start("ob_gzhandler");
$this->buffer = ""; $this->buffer = "";
$this->headers = array(); $this->headers = array();
} }
// --------------------------------------------------------------------------
/** /**
* PHP magic method called when ending the script * PHP magic method called when ending the script
* Used for outputing HTML * Used for outputing HTML
@ -40,14 +38,11 @@ class Output extends miniMVC {
if( ! empty($this->buffer)) if( ! empty($this->buffer))
{ {
ob_start("ob_gzhandler");
echo $this->buffer; echo $this->buffer;
ob_end_flush(); ob_end_flush();
} }
} }
// --------------------------------------------------------------------------
/** /**
* Sets a header for later output * Sets a header for later output
* @param string $key * @param string $key
@ -58,8 +53,6 @@ class Output extends miniMVC {
$this->headers[$key] = $val; $this->headers[$key] = $val;
} }
// --------------------------------------------------------------------------
/** /**
* Adds text to the output buffer * Adds text to the output buffer
* *
@ -70,8 +63,6 @@ class Output extends miniMVC {
$this->buffer .= $string; $this->buffer .= $string;
} }
// --------------------------------------------------------------------------
/** /**
* Sets the output buffer * Sets the output buffer
* *
@ -81,6 +72,28 @@ class Output extends miniMVC {
{ {
$this->buffer = $string; $this->buffer = $string;
} }
/**
* 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();
}
} }
// End of Output.php // End of Output.php