Improved compatiblity with Quercus PHP

This commit is contained in:
Timothy Warren 2012-01-11 10:26:56 -05:00
parent 1f2cafdead
commit aedc4bb31a
7 changed files with 83 additions and 77 deletions

View File

@ -13,7 +13,7 @@
| you will need to add that folder to the document root. | you will need to add that folder to the document root.
| |
*/ */
$document_root = realpath("../".__DIR__); $document_root = './';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -33,7 +33,11 @@ require(APP_PATH.'config/config.php');
require(SYS_PATH . "common.php"); require(SYS_PATH . "common.php");
//Set error handlers //Set error handlers
register_shutdown_function('shutdown'); // Quercus doesn't define error_get_last...
if(function_exists('error_get_last'))
{
register_shutdown_function('shutdown');
}
set_error_handler('on_error'); set_error_handler('on_error');
set_exception_handler('on_exception'); set_exception_handler('on_exception');

View File

@ -5,7 +5,6 @@ class Welcome extends MM_Controller {
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
} }
function index() function index()

View File

@ -22,7 +22,7 @@ class db extends PDO {
private $statement; private $statement;
private static $instance; private static $instance;
public static function get_instance($dbname="default", $options=array()) public static function &get_instance($dbname="default", $options=array())
{ {
if ( ! isset(self::$instance[$dbname])) if ( ! isset(self::$instance[$dbname]))
{ {

View File

@ -199,7 +199,7 @@ class miniMVC extends JSObject{
* *
* @return miniMVC object * @return miniMVC object
*/ */
public static function get_instance() public static function &get_instance()
{ {
if( ! isset(self::$count)) if( ! isset(self::$count))
{ {
@ -306,66 +306,14 @@ class miniMVC extends JSObject{
*/ */
class MM_Controller extends miniMVC { class MM_Controller extends miniMVC {
public $output, $page;
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
$this->output = new Output; $this->output = new Output();
$this->page = new Page; $this->page = new Page();
}
/**
* Function for loading a view
*
* @param string $file
* @param array $data
* @return mixed
*/
function load_view($file, $data, $return=FALSE)
{
$path = "";
// The module is the lower of the class name
// need to figure out a way to allow multiple controllers
// in one module
$module = strtolower(get_class($this));
$not_modules = array('miniMVC', 'page', 'db', 'output');
// If it's a module, look in the module view folder
if( ! in_array($module, $not_modules))
{
$path = MOD_PATH . "{$module}/views/{$file}.php";
}
// If it's not a module, or doesn't exist in the module view folder
// look in the app view folder
if( ! is_file($path))
{
$path = APP_PATH . "views/{$file}.php";
}
// Contain the content for buffering
ob_start();
// Extract the data array
extract($data);
// Include the file
include($path);
$buffer = ob_get_contents();
ob_end_clean();
if($return == TRUE)
{
return $buffer;
}
else
{
$this->output->append_output($buffer);
}
} }
/** /**

View File

@ -15,16 +15,16 @@
/** /**
* Class for displaying output and setting http headers * Class for displaying output and setting http headers
* *
* @extends miniMVC * @extends JSObject
*/ */
class Output extends miniMVC { class Output extends JSObject{
private $buffer, $headers; private $buffer, $headers;
function __construct() function __construct()
{ {
// Compression is good! // Compression is good!
ob_start("ob_gzhandler"); //ob_start("ob_gzhandler");
$this->buffer = ""; $this->buffer = "";
$this->headers = array(); $this->headers = array();
@ -56,7 +56,7 @@ class Output extends miniMVC {
if( ! empty($this->buffer)) if( ! empty($this->buffer))
{ {
echo $this->buffer; echo $this->buffer;
ob_end_flush(); //ob_end_flush();
} }
} }

View File

@ -34,7 +34,8 @@ class Page
$this->body_id = ""; $this->body_id = "";
$this->base = ""; $this->base = "";
$this->mm = miniMVC::get_instance(); $mm =& miniMVC::get_instance();
$this->output =& $mm->output;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -52,7 +53,7 @@ class Page
*/ */
private function _headers($xhtml, $html5) private function _headers($xhtml, $html5)
{ {
$this->mm->output->set_header("Cache-Control", "must-revalidate, public"); $this->output->set_header("Cache-Control", "must-revalidate, public");
$mime = ""; $mime = "";
//Variable for accept keyword //Variable for accept keyword
@ -120,9 +121,9 @@ class Page
} }
// finally, output the mime type and prolog type // finally, output the mime type and prolog type
$this->mm->output->set_header("Content-Type", "{$mime};charset={$charset}"); $this->output->set_header("Content-Type", "{$mime};charset={$charset}");
$this->mm->output->set_header("X-UA-Compatible", "chrome=1, IE=edge"); $this->output->set_header("X-UA-Compatible", "chrome=1, IE=edge");
$this->mm->output->set_output($doctype_string); $this->output->set_output($doctype_string);
return $this; return $this;
} }
@ -351,7 +352,7 @@ class Page
$this->_headers($xhtml, $html5); $this->_headers($xhtml, $html5);
//Output Header //Output Header
$this->mm->load_view('header', $data); $this->load_view('header', $data);
return $this; return $this;
} }
@ -368,7 +369,7 @@ class Page
$data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : ''; $data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : '';
$this->mm->load_view('footer', $data); $this->load_view('footer', $data);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -410,7 +411,7 @@ class Page
$data['stat_class'] = $type; $data['stat_class'] = $type;
$data['message'] = $message; $data['message'] = $message;
return $this->mm->load_view('message', $data, $return); return $this->load_view('message', $data, $return);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -423,8 +424,8 @@ class Page
*/ */
function redirect_303($url) function redirect_303($url)
{ {
$this->mm->output->set_header("HTTP/1.1 303 See Other"); $this->output->set_header("HTTP/1.1 303 See Other");
$this->mm->output->set_header("Location:" . $url); $this->output->set_header("Location:" . $url);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -439,7 +440,7 @@ class Page
function render($view, $data=array()) function render($view, $data=array())
{ {
$this->build_header(); $this->build_header();
$this->mm->load_view($view, $data); $this->load_view($view, $data);
$this->build_footer(); $this->build_footer();
} }
@ -456,7 +457,7 @@ class Page
function output_string($string) function output_string($string)
{ {
$this->build_header(); $this->build_header();
$this->mm->output->append_output($string); $this->output->append_output($string);
$this->build_footer(); $this->build_footer();
} }
@ -501,6 +502,60 @@ class Page
return $string; return $string;
} }
/**
* Function for loading a view
*
* @param string $file
* @param array $data
* @return mixed
*/
function load_view($file, $data, $return=FALSE)
{
$path = "";
// The module is the lower of the class name
// need to figure out a way to allow multiple controllers
// in one module
$module = strtolower(get_class($this));
$not_modules = array('miniMVC', 'page', 'db', 'output');
// If it's a module, look in the module view folder
if( ! in_array($module, $not_modules))
{
$path = MOD_PATH . "{$module}/views/{$file}.php";
}
// If it's not a module, or doesn't exist in the module view folder
// look in the app view folder
if( ! is_file($path))
{
$path = APP_PATH . "views/{$file}.php";
}
// Contain the content for buffering
ob_start();
// Extract the data array
extract($data);
// Include the file
include($path);
$buffer = ob_get_contents();
ob_end_clean();
if($return == TRUE)
{
return $buffer;
}
else
{
$this->output->append_output($buffer);
}
}
} }
// End of page.php // End of page.php