-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHLEngine.php
More file actions
66 lines (62 loc) · 2.12 KB
/
HLEngine.php
File metadata and controls
66 lines (62 loc) · 2.12 KB
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
<?php
class HLEngine {
}
class autoloader {
public static $loader;
public static function init() {
if (self::$loader == NULL)
self::$loader = new self ();
return self::$loader;
}
public function __construct() {
spl_autoload_register ( array ($this, 'model' ) );
spl_autoload_register ( array ($this, 'helper' ) );
spl_autoload_register ( array ($this, 'controller' ) );
spl_autoload_register ( array ($this, 'library' ) );
}
public function library($class) {
set_include_path ( get_include_path () . PATH_SEPARATOR . '/lib/' );
spl_autoload_extensions ( '.library.php' );
spl_autoload ( $class );
}
public function controller($class) {
$class = preg_replace ( '/_controller$/ui', '', $class );
set_include_path ( get_include_path () . PATH_SEPARATOR . '/controller/' );
spl_autoload_extensions ( '.controller.php' );
spl_autoload ( $class );
}
public function model($class) {
$class = preg_replace ( '/_model$/ui', '', $class );
set_include_path ( get_include_path () . PATH_SEPARATOR . '/model/' );
spl_autoload_extensions ( '.model.php' );
spl_autoload ( $class );
}
public function helper($class) {
$class = preg_replace ( '/_helper$/ui', '', $class );
set_include_path ( get_include_path () . PATH_SEPARATOR . '/helper/' );
spl_autoload_extensions ( '.helper.php' );
spl_autoload ( $class );
}
}
//call
autoloader::init ();
function core_autoload($class_name) {
$prefix = substr($class_name,0,2);
switch($prefix){
case 'm_':
$file_name = ROOT_PATH . '/app/models/' . substr($class_name, 2) . '.php';
break;
case 'a_':
$file_name = ROOT_PATH . '/app/actions/' . substr($class_name, 2) . '.php';
break;
case 'u_':
$file_name = ROOT_PATH . '/app/lib/usr/' . substr($class_name, 2) . '.php';
break;
default:
$file_name = get_include_path() . str_replace('_', '/', $class_name).'.php';
}
if( file_exists($file_name) )
require_once $file_name;
else spl_autoload($class_name);
}
spl_autoload_register('core_autoload');