-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoloader.php
34 lines (25 loc) · 919 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
<?php
spl_autoload_register( function ( $class ) {
if ( 0 !== strpos( $class, 'SSA' ) ) {
return;
}
$file_path = explode( '\\', $class );
$file_path[0] = 'php'; //replace the main application namespace with the main folder path
foreach ( $file_path as $k => $v ) {
$v = mb_strtolower( str_replace( '_', '-', $v ) );
$file_path[ $k ] = $v;
}
$file_name = end( $file_path );
if ( false !== array_search( 'interfaces', $file_path ) ) {
$file_name = 'interface-' . $file_name . '.php';
} elseif ( false !== array_search( 'traits', $file_path ) ) {
$file_name = 'trait-' . $file_name . '.php';
} else {
$file_name = 'class-' . $file_name . '.php';
}
$file_path[ count( $file_path ) - 1 ] = $file_name;
$fully_qualified_path = trailingslashit( __DIR__ ) . implode( '/', $file_path );
if ( file_exists( $fully_qualified_path ) ) {
include_once $fully_qualified_path;
}
} );