25 lines
587 B
PHP
25 lines
587 B
PHP
<?php
|
|
|
|
namespace App\Core;
|
|
|
|
final class Autoloader
|
|
{
|
|
public static function register(string $rootPath): void
|
|
{
|
|
spl_autoload_register(static function (string $class) use ($rootPath): void {
|
|
$prefix = 'App\\';
|
|
|
|
if (!str_starts_with($class, $prefix)) {
|
|
return;
|
|
}
|
|
|
|
$relativeClass = substr($class, strlen($prefix));
|
|
$file = $rootPath . '/app/' . str_replace('\\', '/', $relativeClass) . '.php';
|
|
|
|
if (is_file($file)) {
|
|
require_once $file;
|
|
}
|
|
});
|
|
}
|
|
}
|