STB/autoload.php

25 lines
614 B
PHP
Raw Permalink Normal View History

2025-01-15 19:59:49 +01:00
<?php
spl_autoload_register(function ($class) {
$prefix = 'App\\';
// base directory for the namespace $prefix
// __DIR__ entspricht dem aktuellen Pfad
$base_dir = __DIR__ .'/src/';
//$base_dir = "/src/";
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}
$relative_class = substr($class, $len);
$file = ($base_dir . str_replace('\\', '/', $relative_class) . '.php');
if (file_exists($file)) {
require $file;
}
});