<?php
namespace platform\core\Autoload;
class Autoload
{
private array $customs = [
'Plugin' => 'resources/plugins'
];
public function __construct()
{
spl_autoload_register(function ($class){
$path = str_replace('\\', '/', $class . '.php');
if (!$this->load($path)){
$this->custom($path);
}
});
}
private function custom(string $path)
{
$part = explode('/', $path);
if (isset($this->customs[$part[0]])){
$path = str_replace($part[0], $this->customs[$part[0]], $path);
$this->load($path);
}
}
private function load(string $path)
{
if (file_exists($path)){
require_once $path;
return true;
}
return false;
}
}