code clean up
This commit is contained in:
parent
b8560cf14d
commit
5a4973a36c
58
src/mite.php
58
src/mite.php
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mite - A Rapid Prototyping Micro Framework
|
* Mite - A Rapid Prototyping Micro Framework
|
||||||
*
|
*
|
||||||
|
@ -17,29 +18,29 @@
|
||||||
*/
|
*/
|
||||||
class Mite {
|
class Mite {
|
||||||
|
|
||||||
static private $routes = array(); //route-to-class mapping
|
static private $routes = []; // route-to-class mapping
|
||||||
|
|
||||||
static private $index = '/index.php'; //
|
static private $index = '/index.php'; //
|
||||||
|
|
||||||
static private $request = NULL; //url in address bar
|
static private $request = NULL; // url in address bar
|
||||||
|
|
||||||
// for classes
|
// for classes
|
||||||
public $callback = NULL; //class/function
|
public $callback = NULL; // class/function
|
||||||
|
|
||||||
static private $init = NULL; //ah, bad name
|
static private $init = NULL; // ah, bad name
|
||||||
static public $errors = array(); //bites
|
static public $errors = []; // bites
|
||||||
|
|
||||||
// unused
|
// unused
|
||||||
static private $method = NULL; //for RESTish
|
static private $method = NULL; // for REST-ish
|
||||||
static private $options = array(); //Registry
|
static private $options = []; // registry
|
||||||
|
|
||||||
// initilizes framework
|
// initializes framework
|
||||||
public function __construct($config = array())
|
public function __construct($config = [])
|
||||||
{
|
{
|
||||||
$this->init($config);
|
$this->init($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init($config = array())
|
public function init($name, $config = [])
|
||||||
{
|
{
|
||||||
// always set init (can be used as singleton later?)
|
// always set init (can be used as singleton later?)
|
||||||
self::$init = microtime(TRUE);
|
self::$init = microtime(TRUE);
|
||||||
|
@ -98,14 +99,14 @@ class Mite {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// $class = get_class($this); //5 +
|
// $class = get_class($this); // 5 +
|
||||||
// $class = get_called_class(); //5.3
|
// $class = get_called_class(); // 5.3
|
||||||
|
|
||||||
// if(is_callable("{$class}::{$callback}"))
|
// if(is_callable("{$class}::{$callback}"))
|
||||||
if(is_callable(array($this, $callback)))
|
if(is_callable([$this, $callback]))
|
||||||
{
|
{
|
||||||
// return call_user_func("{$class}::{$callback}"); //called staticly 5.2.3+
|
// return call_user_func("{$class}::{$callback}"); // called staticly 5.2.3+
|
||||||
// return call_user_func(array($class, $callback)); //called?
|
// return call_user_func(array($class, $callback)); // called?
|
||||||
return $this->$callback();
|
return $this->$callback();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -143,11 +144,11 @@ class Mite {
|
||||||
{
|
{
|
||||||
if($value === NULL)
|
if($value === NULL)
|
||||||
{
|
{
|
||||||
return $option = isset(self::$options[$key]) ? self::$options[$key] : NULL ;
|
return isset(self::$options[$key]) ? self::$options[$key] : NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $option = isset(self::$options[$key][$value]) ? self::$options[$key][$value] : NULL ;
|
return isset(self::$options[$key][$value]) ? self::$options[$key][$value] : NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,15 +157,15 @@ class Mite {
|
||||||
* State Management
|
* State Management
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/**
|
/**
|
||||||
* Cookie Managment
|
* Cookie Management
|
||||||
*
|
*
|
||||||
* set/get cookies by call signature
|
* set/get cookies by call signature
|
||||||
*/
|
*/
|
||||||
public function cookie($name, $value = NULL, $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly=false)
|
public function cookie($name, $value = NULL, $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly = false)
|
||||||
{
|
{
|
||||||
if($value === NULL)
|
if($value === NULL)
|
||||||
{ // read cookie
|
{ // read cookie
|
||||||
return $cookie = isset($_COOKIE[$name]) ? $_COOKIE[$name] : NULL ;
|
return isset($_COOKIE[$name]) ? $_COOKIE[$name] : NULL ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // create cookie
|
{ // create cookie
|
||||||
|
@ -179,14 +180,14 @@ class Mite {
|
||||||
*/
|
*/
|
||||||
public function flash($name, $value)
|
public function flash($name, $value)
|
||||||
{
|
{
|
||||||
self::cookie($name, $value, $expire = time()+1);
|
self::cookie($name, $value, time()+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function session($key, $value = NULL)
|
public function session($key, $value = NULL)
|
||||||
{
|
{
|
||||||
if($value === NULL)
|
if($value === NULL)
|
||||||
{ // read session
|
{ // read session
|
||||||
return $session = isset($_SESSION[$name]) ? $_SESSION[$name] : NULL ;
|
return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // create session
|
{ // create session
|
||||||
|
@ -205,7 +206,7 @@ class Mite {
|
||||||
{
|
{
|
||||||
$segments = explode('/', trim(self::$request, '/'));
|
$segments = explode('/', trim(self::$request, '/'));
|
||||||
|
|
||||||
return $segment = isset($segments[($number - 1)]) ? $segments[($number - 1)] : NULL;
|
return isset($segments[($number - 1)]) ? $segments[($number - 1)] : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function input($key, $clean = TRUE)
|
public function input($key, $clean = TRUE)
|
||||||
|
@ -224,8 +225,7 @@ class Mite {
|
||||||
|
|
||||||
public function xss($value)
|
public function xss($value)
|
||||||
{
|
{
|
||||||
$value = stripslashes($value);
|
return htmlentities(stripslashes($value));
|
||||||
return htmlentities($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function style($file = NULL)
|
public function style($file = NULL)
|
||||||
|
@ -310,7 +310,7 @@ class Mite {
|
||||||
}
|
}
|
||||||
$output .= "</div>\n";
|
$output .= "</div>\n";
|
||||||
|
|
||||||
// Request varibles
|
// Request variables
|
||||||
$output .= "<div class='dp100 profile'>GET DATA</div>\n";
|
$output .= "<div class='dp100 profile'>GET DATA</div>\n";
|
||||||
foreach($_GET as $key => $value)
|
foreach($_GET as $key => $value)
|
||||||
{
|
{
|
||||||
|
@ -405,11 +405,12 @@ abstract class Mite_Model {
|
||||||
$sql = "INSERT INTO {$this->_table} ";
|
$sql = "INSERT INTO {$this->_table} ";
|
||||||
|
|
||||||
$columns = array();
|
$columns = array();
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
foreach($data as $column => $value)
|
foreach($data as $column => $value)
|
||||||
{
|
{
|
||||||
$columns[] = $column;
|
$columns[] = $column;
|
||||||
$values[] = $value;
|
$values[] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= '(' . implode(',', $columns) . ') ';
|
$sql .= '(' . implode(',', $columns) . ') ';
|
||||||
|
@ -453,6 +454,7 @@ abstract class Mite_Model {
|
||||||
public function find($value)
|
public function find($value)
|
||||||
{
|
{
|
||||||
$sql = "SELECT * FROM {$this->_table} WHERE {$this->_key} = '{$value}'";
|
$sql = "SELECT * FROM {$this->_table} WHERE {$this->_key} = '{$value}'";
|
||||||
|
|
||||||
return $this->db->query($sql);
|
return $this->db->query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue