More header comments\!

This commit is contained in:
Timothy Warren 2012-01-11 14:49:26 -05:00
parent eebe7c8fc8
commit bd1a484f2b
9 changed files with 164 additions and 97 deletions

View File

@ -1,4 +1,17 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/*
|--------------------------------------------------------------------------
| Display Debug backtrace

View File

@ -1,4 +1,16 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
$db_conf = array(
'default' => array(

View File

@ -1,4 +1,16 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* File to configure routes

View File

@ -1,4 +1,20 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* CSS Minifier and Cacher
*/
//Get config files
require('./config/config.php');

View File

@ -1,4 +1,21 @@
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
* @link https://github.com/timw4mail/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* JS Minifier and Cacher
*/
//Get config files
require('./config/config.php');
require('./config/JSMinPlus.php');

View File

@ -20,7 +20,7 @@
class db extends PDO {
private $statement;
private static $instance;
private static $instance = array();
public static function &get_instance($dbname="default", $options=array())
{
@ -67,35 +67,19 @@ class db extends PDO {
$dsn .= ($port !== "") ? ";port={$port}" : "";
}
if($user === "" && $pass === "")
{
$user = null;
$pass = null;
}
$user = ( ! empty($user)) ? $user : null;
$pass = ( ! empty($pass)) ? $pass : null;
// Pre-set the error mode
$opts = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
);
if( ! isset($persist))
{
unset($opts[PDO::ATTR_PERSISTENT]);
}
$options = $opts + $options;
try
{
parent::__construct($dsn, $user, $pass, $options);
}
catch(Exception $e)
{
if($e->getMessage() !== "The auto-commit mode cannot be changed for this driver")
{
get_last_error();
}
}
// Let's try connecting now!
parent::__construct($dsn, $user, $pass, $options);
}
// --------------------------------------------------------------------------

View File

@ -12,10 +12,15 @@
// --------------------------------------------------------------------------
/**
* There should be a generic "Object" class, stdClass is dumb
*/
class Object extends stdClass {}
/**
* Parent class of base class, contains much of the magic
*/
class JSObject {
class JSObject extends Object{
/**
* Constructor for creating the objects
@ -353,6 +358,60 @@ class MM_Controller extends miniMVC {
$this->$file = new $file;
}
}
/**
* 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

@ -38,24 +38,32 @@ class Output extends JSObject{
// Set headers
foreach($this->headers as $key => $val)
{
if( ! empty( $key or $val))
if( ! isset($val))
{
if( ! isset($val))
{
@header($key);
}
else
{
@header("$key: $val");
}
}
@header($key);
}
else
{
@header("$key: $val");
}
}
}
if( ! empty($this->buffer))
{
// Compression is good!
ob_start("ob_gzhandler");
if(function_exists('error_get_last'))
{
if(is_null(error_get_last()))
{
// Compression is good!
ob_start("ob_gzhandler");
}
}
else
{
ob_start();
}
echo $this->buffer;
ob_end_flush();
}

View File

@ -34,8 +34,8 @@ class Page
$this->body_id = "";
$this->base = "";
$mm =& miniMVC::get_instance();
$this->output =& $mm->output;
$this->mm =& miniMVC::get_instance();
$this->output =& $this->mm->output;
}
// --------------------------------------------------------------------------
@ -352,7 +352,7 @@ class Page
$this->_headers($xhtml, $html5);
//Output Header
$this->load_view('header', $data);
$this->mm->load_view('header', $data);
return $this;
}
@ -369,7 +369,7 @@ class Page
$data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : '';
$this->load_view('footer', $data);
$this->mm->load_view('footer', $data);
}
// --------------------------------------------------------------------------
@ -411,7 +411,7 @@ class Page
$data['stat_class'] = $type;
$data['message'] = $message;
return $this->load_view('message', $data, $return);
return $this->mm->load_view('message', $data, $return);
}
// --------------------------------------------------------------------------
@ -440,7 +440,7 @@ class Page
function render($view, $data=array())
{
$this->build_header();
$this->load_view($view, $data);
$this->mm->load_view($view, $data);
$this->build_footer();
}
@ -502,60 +502,6 @@ class Page
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