First commit

This commit is contained in:
Nathan Adams 2014-04-17 22:05:44 -05:00
commit 703a7d5bbd
4 changed files with 204 additions and 0 deletions

2
.htaccess Normal file
View File

@ -0,0 +1,2 @@
RewriteEngine on
RewriteRule ^(.*)$ /index.php/$1 [L]

10
index.php Normal file
View File

@ -0,0 +1,10 @@
<?php
require('system/engine/core.php');
foreach (glob("system/vendor/*.php") as $filename)
{
include $filename;
}
$core = new HF_Core();
$core->run();

63
system/engine/core.php Normal file
View File

@ -0,0 +1,63 @@
<?php
class HF_Core
{
private $class;
private $method;
private $classname;
private $args = array();
public function __construct()
{
$this->findController();
}
private function findController()
{
$request = $_SERVER["REQUEST_URI"];
if ($request == "" || $request == "/")
{
require("../../application/controllers/main.php");
$this->$class = new main();
$this->$method = "index";
$this->$classname = "main";
return;
}
$arr = explode("/", $request);
$path = "../../application/controllers/";
for($i = 0; $i < count($arr); $i++)
{
if ($is_file($path . $arr[$i] . ".php")) // found the controller
{
include($path . $arr[$i] . ".php");
$this->$class = new $arr[$i];
if ($i + 1 != count($arr)) // if there is a define after the controller name - this would be the method name
{
$this->$method = $arr[$i+1];
$this->$args = array_slice ($arr, 2);
$this->$classname = $arr[$i];
} else { // call index
$this->$method = "index";
$this->$classname = $arr[$i];
}
return;
}
if (is_dir($path . $arr[$i])) // controller is hidden deeper
{
$path = $path . $arr[$i] . "/";
continue;
}
// throw exception controller not found
}
}
public function run()
{
$call = new ReflectionFunction($this->$classname, $this->$method);
$call->invokeArgs($this->$class, $this->$args);
}
}

129
system/vendor/DB.php vendored Normal file
View File

@ -0,0 +1,129 @@
<?php
/**
* Provides a database wrapper around the PDO service to help reduce the effort
* to interact with a RDBMS such as SQLite, MySQL, or PostgreSQL.
*
* DB::$c = new PDO($dsn);
*
* @author David Pennington
* @copyright (c) 2012 xeoncross.com
* @license MIT License <http://www.opensource.org/licenses/mit-license.php>
********************************** 80 Columns *********************************
*/
class DB
{
static $q,$c,$p,$i = '`';
/**
* Fetch a column offset from the result set (COUNT() queries)
*
* @param string $query query string
* @param array $params query parameters
* @param integer $key index of column offset
* @return array|null
*/
static function column($query, $params = NULL, $key = 0)
{
if($statement = DB::query($query, $params))
return $statement->fetchColumn($key);
}
/**
* Fetch a single query result row
*
* @param string $query query string
* @param array $params query parameters
* @return mixed
*/
static function row($query, $params = NULL)
{
if($statement = DB::query($query, $params))
return $statement->fetch();
}
/**
* Fetches an associative array of all rows as key-value pairs (first
* column is the key, second column is the value).
*
* @param string $query query string
* @param array $params query parameters
* @return array
*/
static function pairs($query, $params = NULL)
{
$data = array();
if($statement = DB::query($query, $params))
while($row = $statement->fetch(\PDO::FETCH_NUM))
$data[$row[0]] = $row[1];
return $data;
}
/**
* Fetch all query result rows
*
* @param string $query query string
* @param array $params query parameters
* @param int $column the optional column to return
* @return array
*/
static function fetch($query, $params = NULL, $column = NULL)
{
if( ! $statement = DB::query($query, $params)) return;
// Return an array of records
if($column === NULL) return $statement->fetchAll();
// Fetch a certain column from all rows
return $statement->fetchAll(\PDO::FETCH_COLUMN, $column);
}
/**
* Prepare and send a query returning the PDOStatement
*
* @param string $query query string
* @param array $params query parameters
* @return object|null
*/
static function query($query, $params = NULL)
{
$statement = static::$c->prepare(DB::$q[] = strtr($query, '`', DB::$i));
$statement->execute($params);
return $statement;
}
/**
* Insert a row into the database
*
* @param string $table name
* @param array $data
* @return integer|null
*/
static function insert($table, array $data)
{
$query = "INSERT INTO`$table`(`" . implode('`,`', array_keys($data))
. '`)VALUES(' . rtrim(str_repeat('?,', count($data = array_values($data))), ',') . ')';
return DB::$p
? DB::column($query . 'RETURNING`id`', $data)
: (DB::query($query, $data) ? static::$c->lastInsertId() : NULL);
}
/**
* Update a database row
*
* @param string $table name
* @param array $data
* @param array $w where conditions
* @return integer|null
*/
static function update($table, $data, $value, $column = 'id')
{
$keys = implode('`=?,`', array_keys($data));
if($statement = DB::query(
"UPDATE`$table`SET`$keys`=? WHERE`$column`=?",
array_values($data + array($value))
))
return $statement->rowCount();
}
}