-
Notifications
You must be signed in to change notification settings - Fork 2
/
Crystal.php
91 lines (64 loc) · 2.08 KB
/
Crystal.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
<?php
/**
* Crystal
*
* An open source application for database manipulation
*
* @package Crystal
* @author Martin Rusev
* @link http://crystal-project.net
* @since Version 0.5
*
*
*/
// ------------------------------------------------------------------------
/* DEFINE APPLICATION GLOBAL CONSTANTS **/
define('CRYSTAL_DS', DIRECTORY_SEPARATOR);
define('CRYSTAL_BASE', dirname(__FILE__));
define('CRYSTAL_BASEPATH', CRYSTAL_BASE . CRYSTAL_DS . 'Crystal' . CRYSTAL_DS);
define('CRYSTAL_CONFIG', CRYSTAL_BASE . CRYSTAL_DS . 'config' . CRYSTAL_DS . 'database.php');
class Crystal
{
const VERSION = '0.5-alpha';
function __construct()
{
echo "Crystal is static class, no instances allowed";
exit;
}
static public function db($connection = null, $additional_parameters = null)
{
return Crystal_Query_Common::db($connection, $additional_parameters);
}
static public function manipulation($connection = null)
{
return Crystal_Manipulation_Common::db($connection);
}
/** Validation class with new syntax - Crystal 0.4 and beyond **/
static public function validation($rules, $data, $db=null)
{
return new Crystal_Validator($rules, $data, $db);
}
public static function crystal_autoload($class_name)
{
/** LOADS CRYSTAL SPECIFIC CLASSESS ONLY **/
$pattern = '/^Crystal/i';
$match = preg_match($pattern, $class_name, $matches);
if($match != 0 && $match != False)
{
$path = str_replace("_", CRYSTAL_DS, $class_name);
if(file_exists(CRYSTAL_BASE . CRYSTAL_DS . $path . '.php'))
{
include(CRYSTAL_BASE . CRYSTAL_DS . $path . '.php');
}
else
{
throw new Exception("Cannot find requested class " . $class_name . " in " . $path);
}
if(!class_exists($class_name))
{
throw new Exception("Invalid Class name ". $class_name);
}
}
}
}
spl_autoload_register(array('Crystal', 'crystal_autoload'));