-
Notifications
You must be signed in to change notification settings - Fork 2
/
Autoload.php
61 lines (49 loc) · 1.88 KB
/
Autoload.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
<?php
class Wave_Autoload {
public static function register(){
// when unserialising and an undefined class is encountered, call the spl_autoload_call method to
// trigger the autoloader
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(new self, 'autoload'));
include_once WAVE_CORE_PATH . 'Enums.php';
}
/**
* Function to autoload classes
*
* @param $class Class required class
*
*/
static public function autoload($class){
$search_paths = array();
$skip_app = false;
if (substr($class, 0, 5) === 'Wave_') {
$filename = substr($class, 5);
$search_paths[] = WAVE_CORE_PATH . strtr($filename, '_', DS).'.php';
$skip_app = true;
} else if(substr($class, -10) === 'Controller' && $class !== 'Base_Controller'){
$search_paths[] = Wave_Config::get('wave')->path->controllers . strtr(substr($class, 0, -10), '_', DS) . '.php';
} else if (0 === strpos($class, 'Twig')) {
$path = Wave_Config::get('wave')->path->third_party . 'twig' . DS . 'lib' . DS;
$path .= str_replace('_', '/', $class).'.php';
$search_paths[] = $path;
} else {
$search_paths[] = Wave_Config::get('wave')->path->models . strtr($class, '_', DS) . '.php';
$search_paths[] = Wave_Config::get('wave')->path->libraries . strtr($class, '_', DS) . '.php';
}
foreach ($search_paths as $search_path){
if(file_exists($search_path) && include_once($search_path)){
//debug()->addUsedFile($search_path, __FUNCTION__);
return;
}
}
//if still not found, try with alias for model
if(Wave_DB::get() !== null){
$alias_class = Wave_DB::get()->getNamespace().Wave_DB::NS_SEPARATOR.$class;
$filename = Wave_Config::get('wave')->path->models . strtr($alias_class, '_', DS) . '.php';
if(file_exists($filename) && include_once($filename)){
class_alias($alias_class, $class);
}
}
}
}
?>