-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoloader.php
27 lines (25 loc) · 934 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
<?php
class MyAutoloader {
/**
* Static loader method
*
* @param string $class
*/
public static function load( $class ) {
// your classes should be namespaced
// an example could be the class CustomPrefix\controllers\MyController.php
// that should be available in the path: dirname( __FILE__ ) . '/controllers/MyController.php'
$prefix = 'CustomPrefix';
if ( strpos( $class, $prefix ) !== false ) {
$class = str_replace( $prefix, '', $class );
$class = str_replace( '\\', DIRECTORY_SEPARATOR, $class );
require_once dirname( __FILE__ ) . '/' . $class . '.php';
}
}
}
/**
* The autoload-stack could be inactive so the function will return false
*/
if ( in_array( '__autoload', (array)spl_autoload_functions() ) )
spl_autoload_register( '__autoload' );
spl_autoload_register( array( 'MyAutoloader', 'load' ) );