-
Notifications
You must be signed in to change notification settings - Fork 24
/
autoload.php
41 lines (28 loc) · 838 Bytes
/
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
class P2P_Autoload {
protected function __construct( $prefix, $basedir ) {
$this->prefix = $prefix;
$this->basedir = $basedir;
}
static function register( $prefix, $basedir ) {
$loader = new self( $prefix, $basedir );
spl_autoload_register( array( $loader, 'autoload' ) );
}
function autoload( $class ) {
if ( $class[0] === '\\' ) {
$class = substr( $class, 1 );
}
if ( strpos( $class, $this->prefix ) !== 0 ) {
return;
}
$path = str_replace( $this->prefix, '', $class );
$path = str_replace( '_', '-', strtolower( $path ) );
$file = sprintf( '%s/%s.php', $this->basedir, $path );
if ( is_file( $file ) ) {
require $file;
}
}
}
P2P_Autoload::register( 'P2P_', dirname( __FILE__ ) );
require_once dirname( __FILE__ ) . '/util.php';
require_once dirname( __FILE__ ) . '/api.php';