-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoloader.php
More file actions
66 lines (51 loc) · 1.43 KB
/
Copy pathautoloader.php
File metadata and controls
66 lines (51 loc) · 1.43 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
spl_autoload_register('autoload');
function autoload($name): void {
$isPhpBaseType = match($name){
'int' => true,
'bool' => true,
'array' => true,
'string' => true,
'callable' => true,
default => false
};
if($isPhpBaseType) return;
if(str_starts_with($name, basename(dirname(__DIR__,1))))
{
$filePath = "$name.php";
if(load($filePath)) return;
}
$pharClassPath = resolvePharClassPath($name);
if($pharClassPath !== null && file_exists($pharClassPath) && load($pharClassPath)) return;
$filePath = "vendor\\$name.php";
if(load($filePath)) return;
}
function load(string $filename): bool{
if(is_win_os() === false){
$filename = str_replace("\\", "/", $filename);
}
// if(!file_exists($filename)){
// return false;
// }
require_once $filename;
return true;
}
function is_win_os(){
if (strtoupper(substr(PHP_OS_FAMILY, 0, 3)) === 'WIN') {
return true;
}
return false;
}
function resolvePharClassPath(string $name): string | null {
$parts = explode("\\", trim($name, "\\"));
if (count($parts) < 2) return null;
$pharBase = array_shift($parts);
$relativePath = implode("/", $parts);
return "phar://" . __DIR__ . "/" . $pharBase . ".phar/" . $relativePath . ".php";
}
function VAR_DUMP_DEBUG($value){
echo "<pre>";
var_dump($value);
echo "</pre>";
}
?>