Unit test reorganization
This commit is contained in:
parent
860b6abfd6
commit
88236dce0b
@ -1,118 +0,0 @@
|
||||
<?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
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If set to TRUE, a backtrace will be displayed along with php errors.
|
||||
|
|
||||
*/
|
||||
define('SHOW_DEBUG_BACKTRACE', TRUE);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Base Url
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the url path where the framework is located. Requires trailing
|
||||
| slash.
|
||||
|
|
||||
*/
|
||||
define('BASE_URL', $default_baseurl);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Url index file
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This determines whether "index.php" is in generated urls
|
||||
|
|
||||
*/
|
||||
define('URL_INDEX_FILE', 'index.php/');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Content Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the domain used for serving content, such as css, javascript.
|
||||
|
|
||||
*/
|
||||
define('CONTENT_DOMAIN', BASE_URL);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Static Lib Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the path where the 'assets' directory is on the static domain.
|
||||
|
|
||||
*/
|
||||
define('STATIC_LIB_PATH', CONTENT_DOMAIN.'assets/');
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Group Style Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the path that is used to determine the relative path to the
|
||||
| stylesheet minifier. This should not need to be changed.
|
||||
|
|
||||
*/
|
||||
define('STYLE_PATH', STATIC_LIB_PATH . 'css.php/g/');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Group Javascript Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is the path that is used to determine the relative path to the
|
||||
| javascript minifier. This should not need to be changed.
|
||||
|
|
||||
*/
|
||||
define('SCRIPT_PATH', STATIC_LIB_PATH . 'js.php/g/');
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default title
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Default title for webpages
|
||||
|
|
||||
*/
|
||||
define('DEFAULT_TITLE', "miniMVC app");
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default css group
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Default css group
|
||||
|
|
||||
*/
|
||||
define('DEFAULT_CSS_GROUP', "css");
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default js group
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Default js group
|
||||
|
|
||||
*/
|
||||
define('DEFAULT_JS_GROUP', "js");
|
@ -1,25 +0,0 @@
|
||||
<?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(
|
||||
'type' => '',
|
||||
'host' => '',
|
||||
'user' => '',
|
||||
'pass' => '',
|
||||
'db' => '',
|
||||
'prefix' => '',
|
||||
'persist' => '',
|
||||
)
|
||||
);
|
@ -1,32 +0,0 @@
|
||||
<?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
|
||||
*
|
||||
* Routes work on simple/regex matching.
|
||||
*
|
||||
* For a route mapping [http://example.com/]blog to the blog controller in the blog module:
|
||||
* 'blog' => 'blog/blog/index'
|
||||
*
|
||||
* To route a special 404 page, set '404_route' to the "module/controller/method" you wish to use
|
||||
*
|
||||
*/
|
||||
|
||||
return array(
|
||||
// Default Paths
|
||||
'default_controller' => 'welcome',
|
||||
'default_module' => 'welcome',
|
||||
'404_route' => '',
|
||||
);
|
@ -1,7 +0,0 @@
|
||||
<div style="position:relative; margin:0.5em auto; padding:0.5em; width:95%; border:1px solid #924949; background: #f3e6e6;">
|
||||
<h4>A Database Error was encountered</h4>
|
||||
|
||||
<p>Code: <?php echo $code ?></p>
|
||||
<p>Driver Code: <?php echo $driver_code ?></p>
|
||||
<p>Message: <?php echo $message ?></p>
|
||||
</div>
|
@ -1,19 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Error</title>
|
||||
<style type="text/css">
|
||||
div{position:relative; margin:0.5em auto; padding:0.5em; width:95%; border:1px solid #924949; background: #f3e6e6;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="message error">
|
||||
<?php if(isset($title)) : ?>
|
||||
<h1><?php echo $title ?></h1>
|
||||
<?php endif ?>
|
||||
|
||||
<?php echo $message; ?>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,25 +0,0 @@
|
||||
<div style="position:relative; margin:0.5em auto; padding:0.5em; width:95%; border:1px solid #924949; background: #f3e6e6;">
|
||||
<h4>A PHP Error was encountered</h4>
|
||||
|
||||
<p>Severity: <?php echo $severity; ?></p>
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
<p>Filename: <?php echo $filepath; ?></p>
|
||||
<p>Line Number: <?php echo $line; ?></p>
|
||||
|
||||
<?php if(defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
<p>Backtrace: </p>
|
||||
<?php foreach(debug_backtrace() as $error): ?>
|
||||
|
||||
<?php if(isset($error['file']) && ! stristr($error['file'], SYS_PATH)): ?>
|
||||
<p style="margin-left:10px">
|
||||
File: <?php echo str_replace(BASE_PATH, "", $error['file']) ?><br />
|
||||
Line: <?php echo $error['line'] ?><br />
|
||||
Function: <?php echo $error['function'] ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?></p>
|
||||
|
||||
<?php endif ?>
|
||||
</div>
|
@ -1,23 +0,0 @@
|
||||
<div style="position:relative; margin:0.5em auto; padding:0.5em; width:95%; border:1px solid #924949; background: #f3e6e6;">
|
||||
<h4>An uncaught exception was thrown.</h4>
|
||||
|
||||
<p>Message: <?php echo $message; ?></p>
|
||||
|
||||
<?php if(defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE): ?>
|
||||
|
||||
<p>Backtrace: </p>
|
||||
<?php foreach($exception->getTrace() as $error): ?>
|
||||
|
||||
<?php if(isset($error['file']) && ! stristr($error['file'], SYS_PATH)): ?>
|
||||
<p style="margin-left:10px">
|
||||
File: <?php echo str_replace(BASE_PATH, "", $error['file']) ?><br />
|
||||
Line: <?php echo $error['line'] ?><br />
|
||||
Function: <?php echo $error['function'] /*<br />
|
||||
Args: <pre style="margin-left:15px"><?php echo print_r($error['args'], TRUE) ?></pre> */ ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
|
||||
<?php endforeach ?></p>
|
||||
|
||||
<?php endif ?>
|
||||
</div>
|
@ -1,6 +0,0 @@
|
||||
|
||||
<? if($foot_js != ""): ?>
|
||||
<?= $foot_js ?>
|
||||
<? endif ?>
|
||||
</body>
|
||||
</html>
|
@ -1,11 +0,0 @@
|
||||
|
||||
<head>
|
||||
<?= $meta ?>
|
||||
<?= $css ?>
|
||||
<?= $head_tags ?>
|
||||
<title><?= $title ?></title>
|
||||
<? if(!empty($base)) { ?><base href="<?=$base ?>" /><? } ?>
|
||||
<?= $head_tags ?>
|
||||
<?= $head_js ?>
|
||||
</head>
|
||||
<body<?= (!empty($body_class)) ? "class=\"" . $body_class . "\"" : ""; ?><?= (!empty($body_id)) ? " id=\"" . $body_id . "\"" : ""; ?>>
|
@ -1,5 +0,0 @@
|
||||
<div class="message <?= $stat_class ?>">
|
||||
<span class="icon"></span>
|
||||
<?= $message ?>
|
||||
<span class="close" onclick="this.parentElement.style.display='none'"></span>
|
||||
</div>
|
File diff suppressed because it is too large
Load Diff
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Document Root
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The folder where the index of the website exists. In most situations,
|
||||
| this will not need to be changed.
|
||||
|
|
||||
| If the website is in a folder off of the domain name, like:
|
||||
| http://example.com/website/
|
||||
| you will need to add that folder to the document root.
|
||||
|
|
||||
*/
|
||||
$document_root = './';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| CSS Folder
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The folder where css files exist, in relation to the document root
|
||||
|
|
||||
*/
|
||||
$css_root = $document_root. 'css/';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Path from
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Path fragment to rewrite in css files
|
||||
|
|
||||
*/
|
||||
$path_from = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Path to
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The path fragment replacement for the css files
|
||||
|
|
||||
*/
|
||||
$path_to = '';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| JS Folder
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The folder where javascript files exist, in relation to the document root
|
||||
|
|
||||
*/
|
||||
$js_root = $document_root. '/js/';
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/*-----
|
||||
Css
|
||||
-----*/
|
||||
|
||||
'css' => array(
|
||||
'message.css'
|
||||
),
|
||||
|
||||
/*
|
||||
For each group create an array like so
|
||||
|
||||
'my_group' => array(
|
||||
'path/to/css/file1.css',
|
||||
'path/to/css/file2.css'
|
||||
),
|
||||
*/
|
||||
);
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/*
|
||||
For each group create an array like so
|
||||
|
||||
'my_group' => array(
|
||||
'path/to/css/file1.css',
|
||||
'path/to/css/file2.css'
|
||||
),
|
||||
*/
|
||||
);
|
122
assets/css.php
122
assets/css.php
@ -1,122 +0,0 @@
|
||||
<?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');
|
||||
|
||||
//Include the css groups
|
||||
$groups = require("./config/css_groups.php");
|
||||
|
||||
//The name of this file
|
||||
$this_file = 'css.php';
|
||||
|
||||
|
||||
//Function for compressing the CSS as tightly as possible
|
||||
function compress($buffer) {
|
||||
|
||||
//Remove CSS comments
|
||||
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
|
||||
|
||||
//Remove tabs, spaces, newlines, etc.
|
||||
$buffer = preg_replace('`\s+`', ' ', $buffer);
|
||||
$replace = array(
|
||||
' )' => ')',
|
||||
') ' => ')',
|
||||
' }' => '}',
|
||||
'} ' => '}',
|
||||
' {' => '{',
|
||||
'{ ' => '{',
|
||||
', ' => ',',
|
||||
': ' => ':',
|
||||
'; ' => ';',
|
||||
);
|
||||
|
||||
//Eradicate every last space!
|
||||
$buffer = trim(strtr($buffer, $replace));
|
||||
$buffer = str_replace('{ ', '{', $buffer);
|
||||
$buffer = str_replace('} ', '}', $buffer);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
//Creative rewriting
|
||||
$pi = $_SERVER['PATH_INFO'];
|
||||
$pia = explode('/', $pi);
|
||||
|
||||
$pia_len = count($pia);
|
||||
$i = 1;
|
||||
|
||||
while($i < $pia_len)
|
||||
{
|
||||
$j = $i+1;
|
||||
$j = (isset($pia[$j])) ? $j : $i;
|
||||
|
||||
$_GET[$pia[$i]] = $pia[$j];
|
||||
|
||||
$i = $j + 1;
|
||||
};
|
||||
|
||||
$css = '';
|
||||
$modified = array();
|
||||
|
||||
if(isset($groups[$_GET['g']]))
|
||||
{
|
||||
foreach($groups[$_GET['g']] as $file)
|
||||
{
|
||||
$new_file = realpath($css_root.$file);
|
||||
$css .= file_get_contents($new_file);
|
||||
$modified[] = filemtime($new_file);
|
||||
}
|
||||
}
|
||||
|
||||
//Add this page too
|
||||
$modified[] = filemtime($this_file);
|
||||
|
||||
//Get the latest modified date
|
||||
rsort($modified);
|
||||
$last_modified = $modified[0];
|
||||
|
||||
if(!isset($_GET['debug']))
|
||||
{
|
||||
$css = compress($css);
|
||||
}
|
||||
|
||||
$css = strtr($css, $path_from, $path_to);
|
||||
|
||||
$requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: time();
|
||||
|
||||
if($last_modified === $requested_time)
|
||||
{
|
||||
header("HTTP/1.1 304 Not Modified");
|
||||
exit();
|
||||
}
|
||||
|
||||
//This GZIPs the CSS for transmission to the user
|
||||
//making file size smaller and transfer rate quicker
|
||||
ob_start("ob_gzhandler");
|
||||
|
||||
header("Content-Type: text/css; charset=utf8");
|
||||
header("Cache-control: public, max-age=691200, must-revalidate");
|
||||
header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");
|
||||
header("Expires: ".gmdate('D, d M Y H:i:s', (filemtime($this_file) + 691200))." GMT");
|
||||
|
||||
echo $css;
|
||||
|
||||
ob_end_flush();
|
||||
//End of css.php
|
@ -1,36 +0,0 @@
|
||||
.message{
|
||||
position:relative;
|
||||
margin:0.5em auto;
|
||||
padding:0.5em;
|
||||
width:95%;
|
||||
}
|
||||
|
||||
.message .close{
|
||||
width:1em;
|
||||
height:1em;
|
||||
border:1px solid #000;
|
||||
position:absolute;
|
||||
right:0.5em;
|
||||
top:0.5em;
|
||||
}
|
||||
|
||||
.message .icon{
|
||||
left:0.5em;
|
||||
top:0.5em;
|
||||
margin-right:1em;
|
||||
}
|
||||
|
||||
.error{
|
||||
border:1px solid #924949;
|
||||
background: #f3e6e6;
|
||||
}
|
||||
|
||||
.success{
|
||||
border:1px solid #1f8454;
|
||||
background: #70dda9;
|
||||
}
|
||||
|
||||
.info{
|
||||
border:1px solid #bfbe3a;
|
||||
background: #FFFFCC;
|
||||
}
|
161
assets/js.php
161
assets/js.php
@ -1,161 +0,0 @@
|
||||
<?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');
|
||||
|
||||
//Include the js groups
|
||||
$groups_file = "./config/js_groups.php";
|
||||
$groups = require($groups_file);
|
||||
|
||||
//The name of this file
|
||||
$this_file = 'js.php';
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Files
|
||||
*
|
||||
* Concatenates the javascript files for the current
|
||||
* group as a string
|
||||
* @return string
|
||||
*/
|
||||
function get_files()
|
||||
{
|
||||
global $groups, $js_root;
|
||||
|
||||
$js = '';
|
||||
|
||||
foreach($groups[$_GET['g']] as $file)
|
||||
{
|
||||
$new_file = realpath($js_root.$file);
|
||||
$js .= file_get_contents($new_file);
|
||||
}
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Creative rewriting of /g/groupname to ?g=groupname
|
||||
$pi = $_SERVER['PATH_INFO'];
|
||||
$pia = explode('/', $pi);
|
||||
|
||||
$pia_len = count($pia);
|
||||
$i = 1;
|
||||
|
||||
while($i < $pia_len)
|
||||
{
|
||||
$j = $i+1;
|
||||
$j = (isset($pia[$j])) ? $j : $i;
|
||||
|
||||
$_GET[$pia[$i]] = $pia[$j];
|
||||
|
||||
$i = $j + 1;
|
||||
};
|
||||
|
||||
$js = '';
|
||||
$modified = array();
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Aggregate the last modified times of the files
|
||||
if(isset($groups[$_GET['g']]))
|
||||
{
|
||||
$cache_file = $js_root.'/cache/'.$_GET['g'];
|
||||
|
||||
foreach($groups[$_GET['g']] as $file)
|
||||
{
|
||||
$new_file = realpath($js_root.$file);
|
||||
$modified[] = filemtime($new_file);
|
||||
}
|
||||
|
||||
//Add this page too, as well as the groups file
|
||||
$modified[] = filemtime($this_file);
|
||||
$modified[] = filemtime($groups_file);
|
||||
|
||||
$cache_modified = 0;
|
||||
|
||||
//Add the cache file
|
||||
if(is_file($cache_file))
|
||||
{
|
||||
$cache_modified = filemtime($cache_file);
|
||||
}
|
||||
}
|
||||
else //Nothing to display? Just exit
|
||||
{
|
||||
die("You must specify a group that exists");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Get the latest modified date
|
||||
rsort($modified);
|
||||
$last_modified = $modified[0];
|
||||
|
||||
$requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
|
||||
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
: time();
|
||||
|
||||
// If the browser's cached version is up to date,
|
||||
// don't resend the file
|
||||
if($last_modified === $requested_time)
|
||||
{
|
||||
header("HTTP/1.1 304 Not Modified");
|
||||
exit();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//Determine what to do: rebuild cache, send files as is, or send cache.
|
||||
if($cache_modified < $last_modified)
|
||||
{
|
||||
$js = JSMinPlus::minify(get_files());
|
||||
$cs = file_put_contents($cache_file, $js);
|
||||
|
||||
//Make sure cache file gets created/updated
|
||||
if($cs === FALSE)
|
||||
{
|
||||
die("Cache file was not created. Make sure you have the correct folder permissions.");
|
||||
}
|
||||
}
|
||||
else if(isset($_GET['debug']))
|
||||
{
|
||||
$js = get_files();
|
||||
}
|
||||
else
|
||||
{
|
||||
$js = file_get_contents($cache_file);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//This GZIPs the js for transmission to the user
|
||||
//making file size smaller and transfer rate quicker
|
||||
ob_start("ob_gzhandler");
|
||||
|
||||
header("Content-Type: application/javascript; charset=utf8");
|
||||
header("Cache-control: public, max-age=691200, must-revalidate");
|
||||
header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");
|
||||
header("Expires: ".gmdate('D, d M Y H:i:s', (filemtime($this_file) + 691200))." GMT");
|
||||
|
||||
echo $js;
|
||||
|
||||
ob_end_flush();
|
||||
//end of js.php
|
@ -1,46 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class Welcome extends MM_Controller {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
$output = $this->page->set_message('info', "This is just a test message", TRUE);
|
||||
$this->page->output_string($output);
|
||||
}
|
||||
|
||||
function php()
|
||||
{
|
||||
ob_start();
|
||||
phpinfo();
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->output->set_output($output);
|
||||
}
|
||||
|
||||
function reflect()
|
||||
{
|
||||
$this->r = new R($this);
|
||||
|
||||
$obj = $this->r->get_all();
|
||||
|
||||
$this->output->set_output($this->__toString('print_r', $obj));
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Model template class
|
||||
*/
|
||||
class Welcome_Model extends MM_Model{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
402
sys/common.php
402
sys/common.php
@ -1,402 +0,0 @@
|
||||
<?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 including common framework-wide functions
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function to run on script shutdown
|
||||
* -used to catch most fatal errors, and
|
||||
* display them cleanly
|
||||
*/
|
||||
function shutdown()
|
||||
{
|
||||
// Catch the last error
|
||||
$error = error_get_last();
|
||||
|
||||
// types of errors that are fatal
|
||||
$fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
|
||||
|
||||
// Display pretty error page
|
||||
if(in_array($error['type'], $fatal))
|
||||
{
|
||||
$file = str_replace(BASE_PATH, "", $error['file']);
|
||||
|
||||
$err_msg = <<<TXT
|
||||
<h2>Fatal Error: </h2>
|
||||
{$error['message']}<br /><br />
|
||||
<strong>File:</strong> {$file}<br /><br />
|
||||
<strong>Line:</strong> {$error['line']}
|
||||
TXT;
|
||||
show_error($err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Function to search through the tree to find the necessary file
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $curr_path
|
||||
* @return void
|
||||
*/
|
||||
function load_file($file, $curr_path="")
|
||||
{
|
||||
$path = "";
|
||||
|
||||
if($curr_path === "app")
|
||||
{
|
||||
$path = APP_PATH."{$file}.php";
|
||||
}
|
||||
else if($curr_path === "sys")
|
||||
{
|
||||
$path = SYS_PATH."{$file}.php";
|
||||
}
|
||||
else
|
||||
{
|
||||
$path = MOD_PATH."{$curr_path}/{$file}.php";
|
||||
}
|
||||
|
||||
if(is_file($path))
|
||||
{
|
||||
require_once($path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Custom error handler
|
||||
*/
|
||||
function on_error($severity, $message, $filepath, $line, $context)
|
||||
{
|
||||
$levels = array(
|
||||
E_ERROR => 'Error',
|
||||
E_WARNING => 'Warning',
|
||||
E_PARSE => 'Parsing Error',
|
||||
E_NOTICE => 'Notice',
|
||||
E_CORE_ERROR => 'Core Error',
|
||||
E_CORE_WARNING => 'Core Warning',
|
||||
E_COMPILE_ERROR => 'Compile Error',
|
||||
E_COMPILE_WARNING => 'Compile Warning',
|
||||
E_USER_ERROR => 'User Error',
|
||||
E_USER_WARNING => 'User Warning',
|
||||
E_USER_NOTICE => 'User Notice',
|
||||
E_STRICT => 'Strict Error'
|
||||
);
|
||||
|
||||
//Make it prettier
|
||||
$message = highlight_string($message, TRUE);
|
||||
$filepath = str_replace(BASE_PATH, "", $filepath);
|
||||
|
||||
$severity = (isset($levels[$severity])) ? $levels[$severity] : $severity;
|
||||
|
||||
// Contain the content for buffering
|
||||
ob_start();
|
||||
|
||||
include(APP_PATH.'/errors/error_php.php');
|
||||
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $buffer;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Custom exception handlererror_get_last
|
||||
*/
|
||||
function on_exception($exception)
|
||||
{
|
||||
$message = $exception->getMessage();
|
||||
|
||||
//$filepath = str_replace(BASE_PATH, "", $filepath);
|
||||
|
||||
// Contain the content for buffering
|
||||
ob_start();
|
||||
|
||||
include(APP_PATH.'/errors/error_php_exception.php');
|
||||
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $buffer;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Utility function to check if a variable is set, and is an array or object
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return bool
|
||||
*/
|
||||
function is_like_array(&$var)
|
||||
{
|
||||
if( ! isset($var))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (is_array($var) OR is_object($var)) && ( ! empty($var));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* General 404 function
|
||||
*/
|
||||
function show_404()
|
||||
{
|
||||
@header('HTTP/1.1 404 Not Found', TRUE, 404);
|
||||
die('<h1>404 Not Found</h1>');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fatal Error page function
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $status_code
|
||||
*/
|
||||
function show_error($message, $status_code=null)
|
||||
{
|
||||
if( ! is_null($status_code))
|
||||
{
|
||||
@header("HTTP/1.1 {$status_code}", TRUE, (int)$status_code);
|
||||
}
|
||||
|
||||
// Contain the content for buffering
|
||||
ob_start();
|
||||
|
||||
include(APP_PATH.'/errors/error_general.php');
|
||||
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
die($buffer);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns routable methods for the specified controller class
|
||||
*
|
||||
* @param string $controller
|
||||
* @return array
|
||||
*/
|
||||
function controller_methods($controller)
|
||||
{
|
||||
$methods = get_class_methods($controller);
|
||||
$num = count($methods);
|
||||
|
||||
for($i=0; $i < $num; $i++)
|
||||
{
|
||||
$skip_methods = array(
|
||||
'load_file',
|
||||
'on_error',
|
||||
'on_exception',
|
||||
'show_404',
|
||||
'show_error',
|
||||
'controller_methods',
|
||||
'route',
|
||||
'site_url',
|
||||
'load_view',
|
||||
'get_instance',
|
||||
);
|
||||
|
||||
// If the method starts with an underscore, or
|
||||
// is in the blacklist of methods, it is not callable
|
||||
if($methods[$i]{0} === "_" || in_array($methods[$i], $skip_methods))
|
||||
{
|
||||
unset($methods[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Calls the appropriate module/controller/function based on the url
|
||||
*/
|
||||
function route()
|
||||
{
|
||||
$pi = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : null;
|
||||
|
||||
// Load the routes config file
|
||||
$routes = require_once(APP_PATH.'config/routes.php');
|
||||
|
||||
// Set the default route
|
||||
$module = $routes['default_module'];
|
||||
$controller = $routes['default_controller'];
|
||||
$func = "index";
|
||||
$route_set = FALSE;
|
||||
|
||||
// If it isn't the index page
|
||||
if( ! empty($pi) && $pi !== "/")
|
||||
{
|
||||
//Remove trailing slash and begining slash
|
||||
$pi = trim($pi, '/');
|
||||
|
||||
// URL matches the route exactly? Cool, that was easy
|
||||
if(isset($routes[$pi]))
|
||||
{
|
||||
list($module, $controller, $func) = explode("/", $routes[$pi]);
|
||||
$route_set = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
$custom_routes = $routes;
|
||||
|
||||
// Skip required routes
|
||||
unset($custom_routes['default_module']);
|
||||
unset($custom_routes['default_controller']);
|
||||
unset($custom_routes['404_handler']);
|
||||
|
||||
foreach($custom_routes as $uri => $map)
|
||||
{
|
||||
if(preg_match("`{$uri}`i", $pi))
|
||||
{
|
||||
list($module, $controller, $func) = explode("/", $map);
|
||||
$route_set = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Doesn't match a predefined route?
|
||||
// Match on module/controller/method, controller/method, or method
|
||||
if( ! $route_set)
|
||||
{
|
||||
$num_segments = 0;
|
||||
|
||||
if(strpos($pi, '/') === FALSE && ! empty($pi))
|
||||
{
|
||||
$num_segments = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$segments = explode('/', $pi);
|
||||
$num_segments = count($segments);
|
||||
}
|
||||
|
||||
if($num_segments === 1)
|
||||
{
|
||||
$func = $pi;
|
||||
}
|
||||
|
||||
if($num_segments === 2)
|
||||
{
|
||||
list($controller, $func) = $segments;
|
||||
}
|
||||
|
||||
if($num_segments >= 3)
|
||||
{
|
||||
list($module, $controller, $func) = $segments;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$path = MOD_PATH."{$module}/controllers/{$controller}.php";
|
||||
|
||||
if(is_file($path))
|
||||
{
|
||||
require_once($path);
|
||||
|
||||
// Get the list of valid methods for that controller
|
||||
$methods = controller_methods($controller);
|
||||
|
||||
if(in_array($func, $methods))
|
||||
{
|
||||
$class = new $controller;
|
||||
|
||||
return call_user_func(array($class, $func));
|
||||
}
|
||||
|
||||
// Function doesn't exist...404
|
||||
show_404();
|
||||
die();
|
||||
}
|
||||
|
||||
// If it gets here, it's still a 404
|
||||
show_404();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a full url from a url segment
|
||||
*
|
||||
* @param string $segment
|
||||
* @return string
|
||||
*/
|
||||
function site_url($segment)
|
||||
{
|
||||
return $url = BASEURL . URL_INDEX_FILE . $segment;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Wrapper function to simplify using curl
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
function do_curl($url, $options=array())
|
||||
{
|
||||
$cookie = tempnam ("/tmp", "CURLCOOKIE");
|
||||
$ch = curl_init($url);
|
||||
|
||||
//Use the user's User Agent and Cookies
|
||||
$opts= array(
|
||||
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
|
||||
CURLOPT_COOKIEJAR => $cookie,
|
||||
CURLOPT_FOLLOWLOCATION => TRUE,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_RETURNTRANSFER => TRUE,
|
||||
CURLOPT_AUTOREFERER => TRUE,
|
||||
CURLOPT_SSL_VERIFYPEER => FALSE,
|
||||
CURLOPT_CONNECTTIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_PROTOCOLS => array(CURLPROTO_HTTP,CURLPROTO_HTTPS)
|
||||
);
|
||||
|
||||
//Set default options
|
||||
curl_setopt_array($ch, $opts);
|
||||
|
||||
//Set additional options
|
||||
curl_setopt_array($ch, $options);
|
||||
|
||||
return curl_exec($ch);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Load Most Common libraries
|
||||
require_once('miniMVC.php');
|
||||
require_once('output.php');
|
||||
require_once('page.php');
|
||||
require_once('db.php');
|
||||
require_once('r.php');
|
||||
|
||||
// End of common.php
|
263
sys/db.php
263
sys/db.php
@ -1,263 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Extend PHP's PDO class to add some more functionality
|
||||
*
|
||||
* @extends PDO
|
||||
*/
|
||||
class db extends PDO {
|
||||
|
||||
private $statement;
|
||||
private static $instance = array();
|
||||
|
||||
public static function &get_instance($dbname="default", $options=array())
|
||||
{
|
||||
if ( ! isset(self::$instance[$dbname]))
|
||||
{
|
||||
//echo 'Creating new instance of db class.';
|
||||
self::$instance[$dbname] = self::_get_conf($dbname, $options);
|
||||
}
|
||||
|
||||
return self::$instance[$dbname];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Makes DSN from config file, and creates database object
|
||||
*
|
||||
* @param string $dbname
|
||||
* @param array $options
|
||||
* @return db object
|
||||
*/
|
||||
private static function _get_conf($dbname="default", $options=array())
|
||||
{
|
||||
// Include the database config file
|
||||
require(APP_PATH.'config/db.php');
|
||||
|
||||
// Get the correct database in the config file
|
||||
if(is_like_array($db_conf[$dbname]))
|
||||
{
|
||||
// Array manipulation is too verbose
|
||||
extract($db_conf[$dbname]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Apparently the database doesn't exist
|
||||
$this->get_last_error();
|
||||
trigger_error("Database does not exist", E_USER_ERROR);
|
||||
die();
|
||||
}
|
||||
|
||||
// Sqlite doesn't use dbname param
|
||||
$dsn = (stripos($type, "sqlite") === FALSE) ? "{$type}:dbname={$db}" : "{$type}:{$db}";
|
||||
|
||||
// Set hostname if applicable
|
||||
if(isset($host))
|
||||
{
|
||||
$dsn .= ($host !== "") ? ";host={$host}" : "";
|
||||
}
|
||||
|
||||
// Set port if applicable
|
||||
if(isset($port))
|
||||
{
|
||||
$dsn .= ($port !== "") ? ";port={$port}" : "";
|
||||
}
|
||||
|
||||
$user = ( ! empty($user)) ? $user : null;
|
||||
$pass = ( ! empty($pass)) ? $pass : null;
|
||||
|
||||
// Pre-set the error mode
|
||||
$opts = array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
);
|
||||
|
||||
$options = $opts + $options;
|
||||
|
||||
return new db($dsn, $user, $pass, $options);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor to override PDO constructor - Quercus doesn't seem to override
|
||||
* the parent constructor unless the arguments match.
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param string $user
|
||||
* @param string $pass
|
||||
* @param array $options
|
||||
*/
|
||||
function __construct($dsn, $user, $pass, $options)
|
||||
{
|
||||
// Let's try connecting now!
|
||||
parent::__construct($dsn, $user, $pass, $options);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
function __call($name, $args)
|
||||
{
|
||||
if(is_callable($this->$name))
|
||||
{
|
||||
//Add $this to the beginning of the args array
|
||||
array_unshift($args, $this);
|
||||
|
||||
//Call the dynamic function
|
||||
return call_user_func_array($this->$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* PHP magic methods to call non-static methods statically
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
if(is_callable(parent::$name))
|
||||
{
|
||||
return call_user_func_array(parent::$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prints out the contents of the object when used as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function __toString()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$method = ( ! empty($args)) ? $args[0] : "print_r";
|
||||
|
||||
$output = '<pre>';
|
||||
|
||||
if($method == "var_dump")
|
||||
{
|
||||
ob_start();
|
||||
var_dump($this);
|
||||
$output .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
else if($method == "var_export")
|
||||
{
|
||||
ob_start();
|
||||
var_export($this);
|
||||
$output .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= print_r($this, TRUE);
|
||||
}
|
||||
|
||||
return $output . '</pre>';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Simplifies prepared statements for database queries
|
||||
*
|
||||
* @param string $sql
|
||||
* @param array $data
|
||||
* @return mixed PDOStatement / FALSE
|
||||
*/
|
||||
function prepare_query($sql, $data)
|
||||
{
|
||||
// Prepare the sql
|
||||
$query = $this->prepare($sql);
|
||||
|
||||
if( ! is_like_array($query))
|
||||
{
|
||||
$this->get_last_error();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set the statement in the class variable for easy later access
|
||||
$this->statement =& $query;
|
||||
|
||||
|
||||
if( ! is_like_array($data))
|
||||
{
|
||||
trigger_error("Invalid data argument");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Bind the parameters
|
||||
foreach($data as $k => $value)
|
||||
{
|
||||
$res = $query->bindValue($k, $value);
|
||||
|
||||
if( ! $res)
|
||||
{
|
||||
trigger_error("Parameter not successfully bound");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the last error from the database
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_last_error()
|
||||
{
|
||||
$error = array();
|
||||
|
||||
if(isset($this->statement))
|
||||
{
|
||||
$error = $this->statement->errorInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = $this->errorInfo();
|
||||
}
|
||||
|
||||
$code = $error[0];
|
||||
$driver_code = $error[1];
|
||||
$message = $error[2];
|
||||
|
||||
// Contain the content for buffering
|
||||
ob_start();
|
||||
|
||||
include(APP_PATH.'/errors/error_db.php');
|
||||
|
||||
$buffer = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $buffer;
|
||||
}
|
||||
}
|
||||
|
||||
// End of db.php
|
439
sys/miniMVC.php
439
sys/miniMVC.php
@ -1,439 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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 extends Object{
|
||||
|
||||
/**
|
||||
* Constructor for creating the objects
|
||||
*/
|
||||
function __construct($members = array())
|
||||
{
|
||||
// Add the passed parameters to the object
|
||||
foreach($members as $name => $value)
|
||||
{
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
function __call($name, $args)
|
||||
{
|
||||
if(is_callable($this->$name))
|
||||
{
|
||||
//Add $this object to args
|
||||
array_push($args, $this);
|
||||
|
||||
//Call the dynamic function
|
||||
return call_user_func_array($this->$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamically set static methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
if(is_callable(self::$name))
|
||||
{
|
||||
return call_user_func_array(self::$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints out the contents of the object when used as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function __toString()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$method = ( ! empty($args)) ? $args[0] : "print_r";
|
||||
$data = (isset($args[1])) ? $args[1] : array();
|
||||
|
||||
// 32762 == (E_ALL|E_NOTICE|E_STRICT) & ~(E_ERROR | E_PARSE)
|
||||
if(ini_get('error_reporting') == 32762 && empty($data))
|
||||
{
|
||||
$data =& $this;
|
||||
}
|
||||
|
||||
$output = '<pre>';
|
||||
|
||||
if($method == "var_dump")
|
||||
{
|
||||
ob_start();
|
||||
var_dump($data);
|
||||
$output .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
else if($method == "var_export")
|
||||
{
|
||||
ob_start();
|
||||
var_export($data);
|
||||
$output .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= print_r($data, TRUE);
|
||||
}
|
||||
|
||||
return $output . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic class loading
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
function __get($name)
|
||||
{
|
||||
$path = SYS_PATH."{$name}.php";
|
||||
$class = "{$name}";
|
||||
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
if( ! isset($this->$name))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
load_file($name, 'sys');
|
||||
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method that is called when an object is treated as a function
|
||||
*/
|
||||
public static function __invoke()
|
||||
{
|
||||
$class = __CLASS__;
|
||||
return new $class;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base class for the framework
|
||||
*
|
||||
* @extends JSObject
|
||||
*/
|
||||
class miniMVC extends JSObject{
|
||||
|
||||
private static $instance;
|
||||
private static $count;
|
||||
|
||||
/**
|
||||
* Constructor - Any classes loaded here become subclasses of miniMVC
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
self::$instance =& $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method to facilitate dynamic methods
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $args
|
||||
*/
|
||||
function __call($name, $args)
|
||||
{
|
||||
if(is_callable(self::$instance->$name))
|
||||
{
|
||||
//Add $this object to args
|
||||
array_push($args, $this);
|
||||
|
||||
//Call the dynamic function
|
||||
return call_user_func_array(self::$instance->$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function called when cloning an object
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
trigger_error('Clone is not allowed.', E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHP magic method that is called when an object is treated as a function
|
||||
*/
|
||||
public static function __invoke()
|
||||
{
|
||||
return self::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton getter function
|
||||
*
|
||||
* @return miniMVC object
|
||||
*/
|
||||
public static function &get_instance()
|
||||
{
|
||||
if( ! isset(self::$count))
|
||||
{
|
||||
self::$count = 0;
|
||||
}
|
||||
|
||||
if ( ! isset(self::$instance))
|
||||
{
|
||||
self::$count++;
|
||||
self::$instance = new miniMVC;
|
||||
}
|
||||
|
||||
$self =& self::$instance;
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load classes into the singleton
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
function load_class($name, $type='class')
|
||||
{
|
||||
switch($type)
|
||||
{
|
||||
default:
|
||||
$path = APP_PATH . "classes/{$name}.php";
|
||||
break;
|
||||
|
||||
case "sys":
|
||||
$path = SYS_PATH . "{$name}.php";
|
||||
break;
|
||||
}
|
||||
|
||||
// In a subdirectory? No problem
|
||||
if(strpos("/", $name) !== FALSE)
|
||||
{
|
||||
$n = explode("/", $name);
|
||||
$name = $n[count($n) -1];
|
||||
}
|
||||
|
||||
$class = "{$name}";
|
||||
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
if ( ! isset($this->$name))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_file($path))
|
||||
{
|
||||
require_once($path);
|
||||
|
||||
if(class_exists($class, FALSE))
|
||||
{
|
||||
if ( ! isset($this->$name))
|
||||
{
|
||||
$this->$name = new $class;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to remove an object from the singleton
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
function unload($name)
|
||||
{
|
||||
if(isset($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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base Controller Class
|
||||
*
|
||||
* @extends miniMVC
|
||||
*/
|
||||
class MM_Controller extends miniMVC {
|
||||
|
||||
public $output, $page;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->output = new Output();
|
||||
$this->page = new Page();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for loading a model into the current controller
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
function load_model($file, $args=array())
|
||||
{
|
||||
$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}/models/{$file}.php";
|
||||
}
|
||||
|
||||
if(is_file($path))
|
||||
{
|
||||
require_once($path);
|
||||
}
|
||||
|
||||
if( ! empty($args))
|
||||
{
|
||||
|
||||
$this->$file = new $file($args);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base Model Class
|
||||
*
|
||||
* @extends miniMVC
|
||||
*/
|
||||
class MM_Model extends miniMVC {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the database class to the current model class
|
||||
*/
|
||||
function load_db($name="default")
|
||||
{
|
||||
$this->db = db::get_instance($name);
|
||||
}
|
||||
|
||||
}
|
||||
// End of miniMVC.php
|
125
sys/output.php
125
sys/output.php
@ -1,125 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class for displaying output and setting http headers
|
||||
*
|
||||
* @extends JSObject
|
||||
*/
|
||||
class Output extends JSObject{
|
||||
|
||||
private $buffer, $headers;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$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))
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
507
sys/page.php
507
sys/page.php
@ -1,507 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class for building pages
|
||||
*
|
||||
* All methods are chainable, with the exception of the constructor,
|
||||
* build_header(), build_footer(), and _headers() methods.
|
||||
*/
|
||||
class Page
|
||||
{
|
||||
private $meta, $head_js, $foot_js, $css, $title, $head_tags, $body_class, $body_id, $base;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->meta = "";
|
||||
$this->head_js = "";
|
||||
$this->foot_js = "";
|
||||
$this->css = "";
|
||||
$this->title = "";
|
||||
$this->head_tags = "";
|
||||
$this->body_class = "";
|
||||
$this->body_id = "";
|
||||
$this->base = "";
|
||||
|
||||
$this->mm =& miniMVC::get_instance();
|
||||
$this->output =& $this->mm->output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets server headers and doctype
|
||||
*
|
||||
* Also sets page mime type, based on if sent as
|
||||
* html or xhtml, and what the target browser
|
||||
* supports
|
||||
*
|
||||
* @param bool $xhtml
|
||||
* @param bool $html5
|
||||
* @return Page
|
||||
*/
|
||||
private function _headers($xhtml, $html5)
|
||||
{
|
||||
$this->output->set_header("Cache-Control", "must-revalidate, public");
|
||||
$mime = "";
|
||||
|
||||
//Variable for accept keyword
|
||||
$accept = ( ! empty($_SERVER['HTTP_ACCEPT'])) ? $_SERVER['HTTP_ACCEPT'] : "";
|
||||
|
||||
//Predefine doctype
|
||||
$doctype_string = ($html5 == TRUE) ? '<!DOCTYPE html>' : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">';
|
||||
|
||||
//Predefine charset
|
||||
$charset = "UTF-8";
|
||||
|
||||
//If xhtml flag is false, set html5 header
|
||||
if ($xhtml == TRUE)
|
||||
{
|
||||
//Check that the user agent accepts application/xhtml+xml, or if it's the W3C Validator
|
||||
if (stristr($accept, "application/xhtml+xml") || stristr($_SERVER["HTTP_USER_AGENT"], "W3C_Validator"))
|
||||
{
|
||||
$mime = "application/xhtml+xml";
|
||||
}
|
||||
//Or if it supports application/xml
|
||||
else if (stristr($accept, "application/xml"))
|
||||
{
|
||||
$mime = "application/xml";
|
||||
}
|
||||
//Or if it supports text/xml
|
||||
else if (stristr($accept, "text/xml"))
|
||||
{
|
||||
$mime = "text/xml";
|
||||
}
|
||||
else //Otherwise, it's tag soup
|
||||
{
|
||||
$mime = "text/html";
|
||||
|
||||
if ($html5 == FALSE) //If it's not HTML5, it's HTML4
|
||||
{
|
||||
$doctype_string = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mime = "text/html";
|
||||
|
||||
if ($html5 == FALSE)
|
||||
{
|
||||
$doctype_string = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
|
||||
}
|
||||
}
|
||||
|
||||
// set the doctype according to the mime type which was determined
|
||||
if ($mime == "application/xhtml+xml" || $mime == "text/xml" || $mime == "application/xml")
|
||||
{
|
||||
if ($html5 == TRUE)
|
||||
{
|
||||
$doctype_string = '';
|
||||
}
|
||||
|
||||
$doctype_string = "<?xml version='1.0' encoding='$charset' ?>"
|
||||
. $doctype_string
|
||||
. "<html xmlns='http://www.w3.org/1999/xhtml'" . " xml:lang='en'>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$doctype_string .= "<html lang='en'>";
|
||||
}
|
||||
|
||||
// finally, output the mime type and prolog type
|
||||
$this->output->set_header("Content-Type", "{$mime};charset={$charset}");
|
||||
$this->output->set_header("X-UA-Compatible", "chrome=1, IE=edge");
|
||||
$this->output->set_output($doctype_string);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Meta
|
||||
*
|
||||
* Sets meta tags, with codeigniter native meta tag helper
|
||||
*
|
||||
* @param array $meta
|
||||
* @return Page
|
||||
*/
|
||||
public function set_meta($meta)
|
||||
{
|
||||
$this->meta .= $this->_meta($meta);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets minified javascript group in header
|
||||
* @param string $group
|
||||
* @param bool $debug
|
||||
* @return Page
|
||||
*/
|
||||
public function set_head_js_group($group, $debug = FALSE)
|
||||
{
|
||||
if ($group === FALSE)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$file = SCRIPT_PATH . $group;
|
||||
$file .= ($debug == TRUE) ? "/debug/1" : "";
|
||||
$this->head_js .= $this->script_tag($file, FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets a minified css group
|
||||
* @param string $group
|
||||
* @return Page
|
||||
*/
|
||||
public function set_css_group($group)
|
||||
{
|
||||
$link = array(
|
||||
'href' => STYLE_PATH . $group,
|
||||
'rel' => 'stylesheet',
|
||||
'type' => 'text/css'
|
||||
);
|
||||
$this->css .= $this->_link_tag($link);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets a minified javascript group for the page footer
|
||||
* @param string $group
|
||||
* @return Page
|
||||
*/
|
||||
public function set_foot_js_group($group, $debug = FALSE)
|
||||
{
|
||||
$file = SCRIPT_PATH . $group;
|
||||
$file .= ($debug == TRUE) ? "/debug/1" : "";
|
||||
$this->foot_js .= $this->script_tag($file, FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets html title string
|
||||
* @param string $title
|
||||
* @return Page
|
||||
*/
|
||||
public function set_title($title = "")
|
||||
{
|
||||
$title = ($title == "") ? DEFAULT_TITLE : $title;
|
||||
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets custom body class
|
||||
* @param string $class
|
||||
* @return Page
|
||||
*/
|
||||
public function set_body_class($class = "")
|
||||
{
|
||||
$this->body_class = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets custom body id
|
||||
* @param string $id
|
||||
* @return Page
|
||||
*/
|
||||
public function set_body_id($id = "")
|
||||
{
|
||||
$this->body_id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets custom base href
|
||||
* @param string href
|
||||
* @return Page
|
||||
*/
|
||||
public function set_base($href)
|
||||
{
|
||||
$this->base = $href;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets custom css tags
|
||||
* @param string $name
|
||||
* @param string $media
|
||||
* @return Page
|
||||
*/
|
||||
public function set_css_tag($name, $domain = TRUE, $media = "all")
|
||||
{
|
||||
$path = CONTENT_DOMAIN;
|
||||
$css_file = $path . "/css/" . $name . ".css";
|
||||
|
||||
if ($domain == FALSE)
|
||||
{
|
||||
$css_file = $name;
|
||||
}
|
||||
|
||||
$this->css_tags .= $this->_link_tag(array(
|
||||
'rel' => 'stylesheet',
|
||||
'type' => 'text/css',
|
||||
'media' => $media,
|
||||
'href' => $css_file,
|
||||
));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets a custom tag in the header
|
||||
* @param string $tag
|
||||
* @return Page
|
||||
*/
|
||||
public function set_head_tag($tag)
|
||||
{
|
||||
$this->head_tags .= $tag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets custom page header
|
||||
* @param mixed $xhtml
|
||||
* @param bool $html5
|
||||
* @param bool $fbml
|
||||
* @return Page
|
||||
*/
|
||||
public function build_header($xhtml = FALSE, $html5 = TRUE)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
//Set Meta Tags
|
||||
$this->meta = ($html5 == TRUE)
|
||||
? '<meta charset="utf-8" />'. $this->meta
|
||||
: $this->_meta(array(
|
||||
'http-equiv' => 'Content-Type',
|
||||
'content' => 'text/html; charset=utf-8',
|
||||
)) . $this->meta;
|
||||
|
||||
$data['meta'] = $this->meta;
|
||||
|
||||
//Set CSS
|
||||
if ($this->css !== "")
|
||||
{
|
||||
$data['css'] = $this->css;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Set default CSS group
|
||||
$this->set_css_group(DEFAULT_CSS_GROUP);
|
||||
$data['css'] = $this->css;
|
||||
}
|
||||
|
||||
//Set head javascript
|
||||
$data['head_js'] = ( ! empty($this->head_js)) ? $this->head_js : "";
|
||||
|
||||
//Set Page Title
|
||||
$data['title'] = ($this->title !== '') ? $this->title : DEFAULT_TITLE;
|
||||
|
||||
//Set Body Class
|
||||
$data['body_class'] = $this->body_class;
|
||||
|
||||
//Set Body Id
|
||||
$data['body_id'] = $this->body_id;
|
||||
|
||||
//Set Base HREF
|
||||
$data['base'] = $this->base;
|
||||
|
||||
//Set individual head tags
|
||||
$data['head_tags'] = $this->head_tags;
|
||||
|
||||
//Set Server Headers and Doctype
|
||||
$this->_headers($xhtml, $html5);
|
||||
|
||||
//Output Header
|
||||
$this->mm->load_view('header', $data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Builds common footer with any additional js
|
||||
*/
|
||||
public function build_footer()
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : '';
|
||||
|
||||
$this->mm->load_view('footer', $data);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Script Tag
|
||||
*
|
||||
* Helper function for making script tags
|
||||
*
|
||||
* @param string $js
|
||||
* @param bool $domain
|
||||
* @return string
|
||||
*/
|
||||
private function script_tag($js, $domain = TRUE)
|
||||
{
|
||||
$path = CONTENT_DOMAIN;
|
||||
$js_file = $path . "/js/" . $js . ".js";
|
||||
|
||||
if ($domain == FALSE)
|
||||
$js_file = $js;
|
||||
|
||||
$tag = '<script src="' . $js_file . '"></script>';
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Message
|
||||
*
|
||||
* Adds a message to the page
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
public function set_message($type, $message, $return=FALSE)
|
||||
{
|
||||
$data['stat_class'] = $type;
|
||||
$data['message'] = $message;
|
||||
|
||||
return $this->mm->load_view('message', $data, $return);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Redirect 303
|
||||
*
|
||||
* Shortcut function for 303 redirect
|
||||
* @param string $url
|
||||
*/
|
||||
function redirect_303($url)
|
||||
{
|
||||
$this->output->set_header("HTTP/1.1 303 See Other");
|
||||
$this->output->set_header("Location:" . $url);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* Shortcut function for building a page
|
||||
* @param string $view
|
||||
* @param array $data
|
||||
*/
|
||||
function render($view, $data=array())
|
||||
{
|
||||
$this->build_header();
|
||||
$this->mm->load_view($view, $data);
|
||||
$this->build_footer();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Output String
|
||||
*
|
||||
* Similar to render(), this is a shortcut
|
||||
* to output a string in the body of the
|
||||
* page.
|
||||
* @param string $string
|
||||
*/
|
||||
function output_string($string)
|
||||
{
|
||||
$this->build_header();
|
||||
$this->output->append_output($string);
|
||||
$this->build_footer();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Private helper function to generate meta tags
|
||||
*
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
private function _meta($params)
|
||||
{
|
||||
$string = "<meta ";
|
||||
|
||||
foreach($params as $k => $v)
|
||||
{
|
||||
$string .= $k.'="'.$v.'" ';
|
||||
}
|
||||
|
||||
$string .= " />";
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper function to generate link tags
|
||||
*
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
private function _link_tag($params)
|
||||
{
|
||||
$string = "<link ";
|
||||
|
||||
foreach($params as $k => $v)
|
||||
{
|
||||
$string .= $k . '="'.$v.'" ';
|
||||
}
|
||||
|
||||
$string .= " />";
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
// End of page.php
|
64
sys/r.php
64
sys/r.php
@ -1,64 +0,0 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class for examining other classes
|
||||
*
|
||||
* @extends ReflectionClass
|
||||
*/
|
||||
class R extends ReflectionClass {
|
||||
|
||||
public $methods, $properties, $doc_comments, $parent_class, $static_properties, $internal;
|
||||
|
||||
/**
|
||||
* ReflectionClass Constructor
|
||||
*
|
||||
* @param mixed $var
|
||||
*/
|
||||
public function __construct($var)
|
||||
{
|
||||
parent::__construct($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to run static functions in non-static context
|
||||
*/
|
||||
public function __call($name, $args)
|
||||
{
|
||||
if(is_callable($this->$name))
|
||||
{
|
||||
//Add $this object to args
|
||||
array_push($args, $this);
|
||||
|
||||
//Call the dynamic function
|
||||
return call_user_func_array($this->$name, $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve as much information about the class as possible
|
||||
*/
|
||||
public function get_all()
|
||||
{
|
||||
$this->methods = $this->getMethods();
|
||||
$this->properties = $this->getProperties();
|
||||
$this->doc_comments = $this->getDocComment();
|
||||
$this->parent_class = $this->getParentClass();
|
||||
$this->static_properties = $this->getStaticProperties();
|
||||
$this->internal = (int)$this->isInternal();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
9
tests/miniMVCTest.php
Normal file
9
tests/miniMVCTest.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class miniMVCTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
}
|
||||
|
||||
class JSObjectTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user