forked from auraphp/Aura.Auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoload.php
45 lines (37 loc) · 1.18 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
41
42
43
44
45
<?php
spl_autoload_register(function ($class) {
// the package namespace
$ns = 'Aura\Auth';
// what prefixes should be recognized?
$prefixes = array(
"{$ns}\_Config\\" => array(
__DIR__ . '/config',
__DIR__ . '/tests/container/src',
),
"{$ns}\\" => array(
__DIR__ . '/src',
__DIR__ . '/tests/unit/src',
),
);
// go through the prefixes
foreach ($prefixes as $prefix => $dirs) {
// does the requested class match the namespace prefix?
$prefix_len = strlen($prefix);
if (substr($class, 0, $prefix_len) !== $prefix) {
continue;
}
// strip the prefix off the class
$class = substr($class, $prefix_len);
// a partial filename
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
// go through the directories to find classes
foreach ($dirs as $dir) {
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
$file = $dir . DIRECTORY_SEPARATOR . $part;
if (is_readable($file)) {
require $file;
return;
}
}
}
});