-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathautoload.php
49 lines (36 loc) · 1.06 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
<?php
function includes_djb_register( $prefix = null, $basedir = null ) {
static $directories = array();
if( $prefix && $basedir ) {
$directories[$prefix] = $basedir;
}
return $directories;
}
function includes_djb_autoload( $class ) {
static $base_dir = null;
if( null === $base_dir ) {
$base_dir = dirname( __FILE__ );
}
// translate namespaces: PSU\Foo becomes PSU_Foo
$class = str_replace( '\\', '_', $class );
// whitelisting for now, maybe later we just check for the file
$prefix_whitelist = includes_djb_register();
$prefix = null;
if( ( $pos = strpos( $class, '_' ) ) !== false ) {
$prefix = substr( $class, 0, $pos );
} else {
$prefix = $class;
}
if( isset( $prefix_whitelist[$prefix] ) ) {
$file = $prefix_whitelist[$prefix] . '/' . str_replace( '_', '/', $class ) . '.php';
if( file_exists( $file ) ) {
require_once $file;
return;
}
}
}
spl_autoload_register( 'includes_djb_autoload' );
if ( ! defined( 'DJB_LIB_DIR' ) ) {
define( 'DJB_LIB_DIR', dirname(__FILE__) . '/lib' );
}
includes_djb_register( 'DJB', DJB_LIB_DIR );