-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathautoloader.php
33 lines (26 loc) · 931 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
<?php
/**
* PHPCap autoloader.
*
* Modified version of: http://www.php-fig.org/psr/psr-4/examples/
*/
spl_autoload_register(function ($class) {
// PHPCap namespace prefix
$prefix = 'IU\\PHPCap\\';
// Base directory for the namespace prefix
$baseDirectory = __DIR__ . '/src/';
// If the class uses the namespace prefix, then try to load the class
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) === 0) {
// get the relative class name
$relativeClass = substr($class, $len);
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $baseDirectory . str_replace('\\', '/', $relativeClass) . '.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
}
});