forked from Anyape/updatepulse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoload.php
40 lines (33 loc) · 1.45 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
<?php
namespace Anyape\UpdatePulse\Server;
function autoload( $class_name ) {
static $f_root = UPSERV_PLUGIN_PATH;
static $ns_root = __NAMESPACE__;
static $class_map = array();
$path = false;
$class_map = empty( $class_map ) ? array(
$ns_root => $f_root . 'inc/class-upserv.php',
'Anyape\\Utils\\Utils' => $f_root . 'inc/class-utils.php',
'Anyape\\Crypto\\Crypto' => $f_root . 'lib/anyape-crypto/crypto.php',
'Anyape\\Parsedown' => $f_root . 'lib/parsedown/Parsedown.php',
'Anyape\\UpdatePulse\\Package_Parser\\Parser' => $f_root . 'lib/anyape-package-parser/package-parser.php',
'PhpS3\\PhpS3' => $f_root . 'lib/PhpS3/PhpS3.php',
) : $class_map;
if ( isset( $class_map[ $class_name ] ) && ! class_exists( $class_name, false ) ) {
$path = $class_map[ $class_name ];
}
if ( ! $path && 0 === strpos( $class_name, $ns_root ) ) {
$ns_frags = explode( '\\', str_replace( $ns_root, '', $class_name ) );
$class_frag = str_replace( '_', '-', strtolower( array_pop( $ns_frags ) ) );
$path_frags = str_replace(
'_',
'-',
strtolower( implode( '/', $ns_frags ) )
);
$path = $f_root . 'inc/' . $path_frags . '/class-' . $class_frag . '.php';
}
if ( $path && file_exists( $path ) && is_readable( $path ) ) {
include $path;
}
}
spl_autoload_register( 'Anyape\UpdatePulse\Server\autoload' );