Code style consistency improvements

This commit is contained in:
Timothy Warren 2012-05-18 13:52:12 -04:00
parent 134d1091a9
commit 8e97f37fe0
13 changed files with 96 additions and 96 deletions

View File

@ -131,3 +131,5 @@ define('DEFAULT_CSS_GROUP', "css");
| |
*/ */
define('DEFAULT_JS_GROUP', "js"); define('DEFAULT_JS_GROUP', "js");
// End of config.php

View File

@ -33,3 +33,5 @@ $db_conf = [
'file' => '', 'file' => '',
] ]
]; ];
// End of db.php

View File

@ -18,7 +18,7 @@
* *
* Routes work on simple/regex matching. * Routes work on simple/regex matching.
* *
* For a route mapping [http://example.com/]blog to the blog controller in the blog module: * For a route mapping http://example.com/blog to the blog controller in the blog module:
* 'blog' => 'blog/blog/index' * 'blog' => 'blog/blog/index'
* *
* To route a special 404 page, set '404_route' to the "module/controller/method" you wish to use * To route a special 404 page, set '404_route' to the "module/controller/method" you wish to use
@ -35,3 +35,5 @@ return [
'default_module' => 'welcome', 'default_module' => 'welcome',
'404_route' => '', '404_route' => '',
]; ];
// End of routes.php

View File

@ -55,4 +55,5 @@ class Welcome extends MM_Controller {
$this->page->set_output($output); $this->page->set_output($output);
} }
} }
// End of welcome.php // End of welcome.php

View File

@ -28,3 +28,5 @@ class Welcome_Model extends MM_Model{
parent::__construct(); parent::__construct();
} }
} }
// End of welcome_model.php

View File

@ -88,7 +88,7 @@ $modified = [];
if (isset($groups[$_GET['g']])) if (isset($groups[$_GET['g']]))
{ {
foreach($groups[$_GET['g']] as &$file) foreach ($groups[$_GET['g']] as &$file)
{ {
$new_file = $css_root.$file; $new_file = $css_root.$file;
$css .= file_get_contents($new_file); $css .= file_get_contents($new_file);
@ -103,7 +103,7 @@ $modified[] = filemtime($this_file);
rsort($modified); rsort($modified);
$last_modified = $modified[0]; $last_modified = $modified[0];
$requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $requested_time= (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])
: time(); : time();

View File

@ -45,7 +45,7 @@ function get_files()
$js = ''; $js = '';
foreach($groups[$_GET['g']] as &$file) foreach ($groups[$_GET['g']] as &$file)
{ {
$new_file = realpath($js_root.$file); $new_file = realpath($js_root.$file);
$js .= file_get_contents($new_file); $js .= file_get_contents($new_file);
@ -84,7 +84,7 @@ $pia = explode('/', $pi);
$pia_len = count($pia); $pia_len = count($pia);
$i = 1; $i = 1;
while($i < $pia_len) while ($i < $pia_len)
{ {
$j = $i+1; $j = $i+1;
$j = (isset($pia[$j])) ? $j : $i; $j = (isset($pia[$j])) ? $j : $i;
@ -104,7 +104,7 @@ if (isset($groups[$_GET['g']]))
{ {
$cache_file = $js_root.'cache/'.$_GET['g']; $cache_file = $js_root.'cache/'.$_GET['g'];
foreach($groups[$_GET['g']] as &$file) foreach ($groups[$_GET['g']] as &$file)
{ {
$new_file = realpath($js_root.$file); $new_file = realpath($js_root.$file);
$modified[] = filemtime($new_file); $modified[] = filemtime($new_file);
@ -159,7 +159,7 @@ if ($cache_modified < $last_modified)
die("Cache file was not created. Make sure you have the correct folder permissions."); die("Cache file was not created. Make sure you have the correct folder permissions.");
} }
} }
else if (isset($_GET['debug'])) elseif (isset($_GET['debug']))
{ {
$js = get_files(); $js = get_files();
} }
@ -184,4 +184,5 @@ header("Expires: ".gmdate('D, d M Y H:i:s', (filemtime($this_file) + 691200))."
echo $js; echo $js;
ob_end_flush(); ob_end_flush();
//end of js.php //end of js.php

View File

@ -213,7 +213,7 @@ function to_string($data, $method='print_r')
$output .= ob_get_contents(); $output .= ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
else if ($method == "var_export") elseif ($method == "var_export")
{ {
ob_start(); ob_start();
var_export($data); var_export($data);

View File

@ -33,7 +33,7 @@ class MM extends ArrayObject {
parent::__construct($members); parent::__construct($members);
// Add the passed parameters to the object // Add the passed parameters to the object
foreach($members as $name => &$value) foreach ($members as $name => &$value)
{ {
$this->$name = $value; $this->$name = $value;
} }
@ -59,7 +59,7 @@ class MM extends ArrayObject {
} }
// Allow dynamic method calls // Allow dynamic method calls
if(is_callable($this->$name)) if (is_callable($this->$name))
{ {
//Call the dynamic function //Call the dynamic function
return call_user_func_array($this->$name, $params); return call_user_func_array($this->$name, $params);

View File

@ -21,7 +21,7 @@
*/ */
class DB extends Query_Builder { class DB extends Query_Builder {
use JSObject; use Generic;
/** /**
* DB connection instances * DB connection instances
@ -62,33 +62,6 @@ class DB extends Query_Builder {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Constructor to override JSObject trait
*
* @param array $params
*/
public function __construct(array $params=[])
{
// Let's try connecting now!
parent::__construct($params);
}
// --------------------------------------------------------------------------
/**
* Override __call in trait to call __call in Query Builder...lol
*
* @param string $name
* @param array $params
* @return mixed
*/
public function __call($name, $params=[])
{
return parent::__call($name, $params);
}
// --------------------------------------------------------------------------
/** /**
* Returns the last error from the database * Returns the last error from the database
* *

View File

@ -131,7 +131,7 @@ class MM_Output extends MM {
public function flush_headers() public function flush_headers()
{ {
// Set headers // Set headers
foreach($this->headers as $key => &$val) foreach ($this->headers as $key => &$val)
{ {
if ( ! isset($val)) if ( ! isset($val))
{ {

View File

@ -420,7 +420,9 @@ class MM_Page extends MM_Output {
$js_file = "{$path}/js/{$js}.js"; $js_file = "{$path}/js/{$js}.js";
if ($domain == FALSE) if ($domain == FALSE)
{
$js_file = $js; $js_file = $js;
}
$tag = '<script src="' . $js_file . '"></script>'; $tag = '<script src="' . $js_file . '"></script>';
@ -505,7 +507,7 @@ class MM_Page extends MM_Output {
{ {
$string = "<meta "; $string = "<meta ";
foreach($params as $k => &$v) foreach ($params as $k => &$v)
{ {
$string .= $k.'="'.$v.'" '; $string .= $k.'="'.$v.'" ';
} }
@ -527,7 +529,7 @@ class MM_Page extends MM_Output {
{ {
$string = "<link "; $string = "<link ";
foreach($params as $k => &$v) foreach ($params as $k => &$v)
{ {
$string .= $k . '="'.$v.'" '; $string .= $k . '="'.$v.'" ';
} }

View File

@ -11,6 +11,66 @@
* @license http://philsturgeon.co.uk/code/dbad-license * @license http://philsturgeon.co.uk/code/dbad-license
*/ */
// --------------------------------------------------------------------------
// ! Generic Trait
// --------------------------------------------------------------------------
/**
* Simple Trait to include the toString() magic method
*
* @package miniMVC
* @subpackage System
*/
trait Generic {
/**
* Prints out the contents of the object when used as a string
*
* @return string
*/
public function __toString()
{
if (ENVIRONMENT == 'DEVELOPMENT')
{
$args = func_get_args();
$method = ( ! empty($args)) ? $args[0] : "print_r";
$data = (isset($args[1])) ? $args[1] : [];
if (empty($data))
{
$data =& $this;
}
$output = '<pre>';
if ($method == "var_dump")
{
ob_start();
var_dump($data);
$output .= ob_get_contents();
ob_end_clean();
}
elseif ($method == "var_export")
{
ob_start();
var_export($data);
$output .= ob_get_contents();
ob_end_clean();
}
else
{
$output .= print_r($data, TRUE);
}
return $output . '</pre>';
}
else
{
return '';
}
}
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// ! JSObject Trait // ! JSObject Trait
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -23,6 +83,8 @@
*/ */
trait JSObject { trait JSObject {
use Generic;
/** /**
* Constructor for creating the objects * Constructor for creating the objects
* *
@ -48,7 +110,7 @@ trait JSObject {
*/ */
public function __call($name, $params = []) public function __call($name, $params = [])
{ {
if(is_callable($this->$name)) if (is_callable($this->$name))
{ {
//Call the dynamic function //Call the dynamic function
return call_user_func_array($this->$name, $params); return call_user_func_array($this->$name, $params);
@ -57,55 +119,6 @@ trait JSObject {
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Prints out the contents of the object when used as a string
*
* @return string
*/
public function __toString()
{
if(ENVIRONMENT == 'DEVELOPMENT')
{
$args = func_get_args();
$method = ( ! empty($args)) ? $args[0] : "print_r";
$data = (isset($args[1])) ? $args[1] : [];
if(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>';
}
else
{
return '';
}
}
// --------------------------------------------------------------------------
/** /**
* PHP magic method that is called when an object is treated as a function * PHP magic method that is called when an object is treated as a function
* *
@ -130,6 +143,8 @@ trait JSObject {
*/ */
trait Singleton { trait Singleton {
use Generic;
/** /**
* Singleton object * Singleton object
* *