code clean up

This commit is contained in:
Geoff Doty 2023-06-23 12:11:47 -05:00
parent b8560cf14d
commit 5a4973a36c
1 changed files with 30 additions and 28 deletions

View File

@ -1,5 +1,6 @@
<?php
/**
* Mite - A Rapid Prototyping Micro Framework
*
@ -17,29 +18,29 @@
*/
class Mite {
static private $routes = array(); //route-to-class mapping
static private $routes = []; // route-to-class mapping
static private $index = '/index.php'; //
static private $request = NULL; //url in address bar
static private $request = NULL; // url in address bar
// for classes
public $callback = NULL; //class/function
public $callback = NULL; // class/function
static private $init = NULL; //ah, bad name
static public $errors = array(); //bites
static private $init = NULL; // ah, bad name
static public $errors = []; // bites
// unused
static private $method = NULL; //for RESTish
static private $options = array(); //Registry
static private $method = NULL; // for REST-ish
static private $options = []; // registry
// initilizes framework
public function __construct($config = array())
// initializes framework
public function __construct($config = [])
{
$this->init($config);
}
public function init($config = array())
public function init($name, $config = [])
{
// always set init (can be used as singleton later?)
self::$init = microtime(TRUE);
@ -98,14 +99,14 @@ class Mite {
}
else
{
// $class = get_class($this); //5 +
// $class = get_called_class(); //5.3
// $class = get_class($this); // 5 +
// $class = get_called_class(); // 5.3
// 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(array($class, $callback)); //called?
// return call_user_func("{$class}::{$callback}"); // called staticly 5.2.3+
// return call_user_func(array($class, $callback)); // called?
return $this->$callback();
}
else
@ -143,11 +144,11 @@ class Mite {
{
if($value === NULL)
{
return $option = isset(self::$options[$key]) ? self::$options[$key] : NULL ;
return isset(self::$options[$key]) ? self::$options[$key] : NULL;
}
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
*****************************************************************/
/**
* Cookie Managment
* Cookie Management
*
* 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)
{ // read cookie
return $cookie = isset($_COOKIE[$name]) ? $_COOKIE[$name] : NULL ;
return isset($_COOKIE[$name]) ? $_COOKIE[$name] : NULL ;
}
else
{ // create cookie
@ -179,14 +180,14 @@ class Mite {
*/
public function flash($name, $value)
{
self::cookie($name, $value, $expire = time()+1);
self::cookie($name, $value, time()+1);
}
public function session($key, $value = NULL)
{
if($value === NULL)
{ // read session
return $session = isset($_SESSION[$name]) ? $_SESSION[$name] : NULL ;
return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL ;
}
else
{ // create session
@ -205,7 +206,7 @@ class Mite {
{
$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)
@ -224,8 +225,7 @@ class Mite {
public function xss($value)
{
$value = stripslashes($value);
return htmlentities($value);
return htmlentities(stripslashes($value));
}
public function style($file = NULL)
@ -310,7 +310,7 @@ class Mite {
}
$output .= "</div>\n";
// Request varibles
// Request variables
$output .= "<div class='dp100 profile'>GET DATA</div>\n";
foreach($_GET as $key => $value)
{
@ -405,11 +405,12 @@ abstract class Mite_Model {
$sql = "INSERT INTO {$this->_table} ";
$columns = array();
$values = array();
$values = array();
foreach($data as $column => $value)
{
$columns[] = $column;
$values[] = $value;
$values[] = $value;
}
$sql .= '(' . implode(',', $columns) . ') ';
@ -453,6 +454,7 @@ abstract class Mite_Model {
public function find($value)
{
$sql = "SELECT * FROM {$this->_table} WHERE {$this->_key} = '{$value}'";
return $this->db->query($sql);
}