Haplous Framework 

Haplous Framework Commit Details


Date:2014-04-17 22:05:44 (10 years 8 months ago)
Author:Natalie Adams
Branch:master
Commit:703a7d5bbdb73ad38d5f1f56808cbd68fcb0d292
Message:First commit

Changes:

File differences

.htaccess
1
2
RewriteEngine on
RewriteRule ^(.*)$ /index.php/$1 [L]
index.php
1
2
3
4
5
6
7
8
9
10
<?php
require('system/engine/core.php');
foreach (glob("system/vendor/*.php") as $filename)
{
include $filename;
}
$core = new HF_Core();
$core->run();
system/engine/core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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);
}
}
system/vendor/DB.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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);
*
* @authorDavid Pennington
* @copyright(c) 2012 xeoncross.com
* @licenseMIT 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();
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.06843s using 14 queries.