-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoloader.php
37 lines (30 loc) · 930 Bytes
/
autoloader.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
<?php
/**
* Autoloads classes at configured directories/namespaces
*
* @param $class
*/
function flexwalker_autoloader( $class ) {
$base_dir = __DIR__;
$lower = strtolower( $class );
// array items: namespaced directories: [ directory, namespace ] otherwise: [ directory ]
$dirs = [
[ DIRECTORY_SEPARATOR . 'code' . DIRECTORY_SEPARATOR, FLXW, ],
];
// check to see if the class being asked for is in dir above
foreach ( $dirs as $dir ) {
if ( isset( $dir[1] ) && $dir[1] ) {
$class = str_replace( $dir[1], '', $class );
$lower = strtolower( str_replace( $dir[1], '', $class ) );
}
$file = $base_dir . $dir[0] . str_replace( '\\', '', $class ) . '.php';
$filelower = $base_dir . $dir[0] . str_replace( '\\', '', $lower ) . '.php';
if ( file_exists( $file ) ) {
require $file;
break;
} else if ( file_exists( $filelower ) ) {
require $filelower;
break;
}
}
}