generated from Pierre-Lannoy/wp-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathautoload.php
More file actions
54 lines (52 loc) · 1.9 KB
/
autoload.php
File metadata and controls
54 lines (52 loc) · 1.9 KB
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
<?php
/**
* Autoload for DecaLog.
*
* @package Bootstrap
* @author Pierre Lannoy <https://pierre.lannoy.fr/>.
* @since 1.0.0
*/
spl_autoload_register(
function ( $class ) {
$paths = array(
'Decalog\\System\\' => DECALOG_INCLUDES_DIR . 'system/',
'Decalog\\Plugin\\Feature\\' => DECALOG_INCLUDES_DIR . 'features/',
'Decalog\\Plugin\\' => DECALOG_INCLUDES_DIR . 'plugin/',
'Decalog\\Processor\\' => DECALOG_INCLUDES_DIR . 'processors/',
'Decalog\\Handler\\' => DECALOG_INCLUDES_DIR . 'handlers/',
'Decalog\\Storage\\' => DECALOG_INCLUDES_DIR . 'storage/',
'Decalog\\Formatter\\' => DECALOG_INCLUDES_DIR . 'formatters/',
'Decalog\\Listener\\WP_CLI\\' => DECALOG_INCLUDES_DIR . 'listeners/wp-cli/',
'Decalog\\Listener\\' => DECALOG_INCLUDES_DIR . 'listeners/',
'Decalog\\Panel\\' => DECALOG_INCLUDES_DIR . 'panels/',
'Decalog\\Library\\' => DECALOG_VENDOR_DIR,
'Decalog\\Integration\\' => DECALOG_INCLUDES_DIR . 'integrations/',
'Decalog\\API\\' => DECALOG_INCLUDES_DIR . 'api/',
'Decalog\\' => DECALOG_INCLUDES_DIR . 'api/',
);
$classname = $class;
$filepath = __DIR__ . '/';
if ( strpos( $classname, 'Decalog\\' ) === 0 ) {
while ( strpos( $classname, '\\' ) !== false ) {
$classname = substr( $classname, strpos( $classname, '\\' ) + 1, 1000 );
}
$filename = 'class-' . str_replace( '_', '-', strtolower( $classname ) ) . '.php';
foreach ( $paths as $prefix => $dir ) {
if ( strpos( $class, $prefix ) === 0 ) {
$filepath = $dir;
break;
}
}
if ( strpos( $filename, '-public' ) !== false ) {
$filepath = DECALOG_PUBLIC_DIR;
}
if ( strpos( $filename, '-admin' ) !== false ) {
$filepath = DECALOG_ADMIN_DIR;
}
$file = $filepath . $filename;
if ( file_exists( $file ) ) {
include_once $file;
}
}
}
);