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 <?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 | Display Debug backtrace

View File

@ -1,4 +1,16 @@
<?php <?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( $db_conf = array(
'default' => array( 'default' => array(

View File

@ -1,4 +1,16 @@
<?php <?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 * File to configure routes

View File

@ -1,4 +1,20 @@
<?php <?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 //Get config files
require('./config/config.php'); require('./config/config.php');

View File

@ -1,4 +1,21 @@
<?php <?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 //Get config files
require('./config/config.php'); require('./config/config.php');
require('./config/JSMinPlus.php'); require('./config/JSMinPlus.php');

View File

@ -20,7 +20,7 @@
class db extends PDO { class db extends PDO {
private $statement; private $statement;
private static $instance; private static $instance = array();
public static function &get_instance($dbname="default", $options=array()) public static function &get_instance($dbname="default", $options=array())
{ {
@ -67,34 +67,18 @@ class db extends PDO {
$dsn .= ($port !== "") ? ";port={$port}" : ""; $dsn .= ($port !== "") ? ";port={$port}" : "";
} }
if($user === "" && $pass === "") $user = ( ! empty($user)) ? $user : null;
{ $pass = ( ! empty($pass)) ? $pass : null;
$user = null;
$pass = null;
}
// Pre-set the error mode
$opts = array( $opts = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
); );
if( ! isset($persist))
{
unset($opts[PDO::ATTR_PERSISTENT]);
}
$options = $opts + $options; $options = $opts + $options;
try // Let's try connecting now!
{ parent::__construct($dsn, $user, $pass, $options);
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();
}
}
} }

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 * Parent class of base class, contains much of the magic
*/ */
class JSObject { class JSObject extends Object{
/** /**
* Constructor for creating the objects * Constructor for creating the objects
@ -353,6 +358,60 @@ class MM_Controller extends miniMVC {
$this->$file = new $file; $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 // Set headers
foreach($this->headers as $key => $val) foreach($this->headers as $key => $val)
{ {
if( ! empty( $key or $val)) if( ! isset($val))
{ {
if( ! isset($val)) @header($key);
{ }
@header($key); else
} {
else @header("$key: $val");
{
@header("$key: $val");
}
} }
} }
} }
if( ! empty($this->buffer)) if( ! empty($this->buffer))
{ {
// Compression is good! if(function_exists('error_get_last'))
ob_start("ob_gzhandler"); {
if(is_null(error_get_last()))
{
// Compression is good!
ob_start("ob_gzhandler");
}
}
else
{
ob_start();
}
echo $this->buffer; echo $this->buffer;
ob_end_flush(); ob_end_flush();
} }

View File

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