<?php
class Autoload
{
private array $prefixes = [
'prefix' => 'path/to/folder'
];
public function __construct()
{
spl_autoload_register(function ($class){
$this->load($this->getPath($class));
});
}
private function getPath(string $class)
{
return str_replace('\\', '/', $this->has($class) . '.php');
}
private function has(string $class)
{
$path = explode('\\', $class);
if (isset($this->prefixes[$path[0]])){
$class = str_replace($path[0], $this->prefixes[$path[0]], $class);
}
return $class;
}
private function load(string $path)
{
if (file_exists($path)) {
require_once $path;
}
}
}
Есть недостатки и ошибки?