-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__autoload.php
44 lines (33 loc) · 1022 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
41
42
43
44
<?php
function pls_autoload(string|null $namespace = null, string|null $dir = null)
{
static $structures = [];
if (!is_null($namespace) && !is_null($dir)) {
$structures[$namespace] = $dir;
}
return $structures;
}
spl_autoload_register(function ($class) {
$structure = pls_autoload();
foreach ($structure as $namespace => $dir) {
if (!str_starts_with(strtolower($class), strtolower($namespace))) {
continue;
}
$class = ltrim($class, $namespace);
$classPath = join_paths($dir, "$class.php");
$classPathDefault = join_paths($dir, $class, basename($class) . ".php");
$classPath = regular_url($classPath);
$classPathDefault = regular_url($classPathDefault);
if (file_exists($classPath)) {
include_once $classPath;
} else if (file_exists($classPathDefault)) {
include_once $classPathDefault;
} else {
continue;
}
return;
}
// NO Autoload found!
});
// Default Autoloads: Pluslib
pls_autoload('pluslib\\', __DIR__.'/pluslib');