19 lines
620 B
PHP
19 lines
620 B
PHP
<?php
|
|
|
|
spl_autoload_register(callback: function ($className) {
|
|
$prefix = 'App';
|
|
$baseDir = __DIR__;
|
|
|
|
$prefixLen = strlen(string: $prefix);
|
|
if (strncmp(string1: $prefix, string2: $className, length: $prefixLen) !== 0) {
|
|
die("Invalid class: $className");
|
|
}
|
|
$realClassNamePSRpath = substr(string: $className, offset: $prefixLen);
|
|
$classLocation = $baseDir . str_replace(search: '\\', replace: '/', subject: $realClassNamePSRpath) . '.php';
|
|
if (file_exists(filename: $classLocation)) {
|
|
require $classLocation;
|
|
} else {
|
|
die("Invalid class: $className");
|
|
}
|
|
});
|