1
0
Fork 0

Add simple PSR-4 autoloader

master
Anonymous Contributor 2023-08-29 13:53:32 +02:00
parent 6c22684b2f
commit 024a140609
1 changed files with 27 additions and 0 deletions

27
app/autoload.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace Mcp;
class Autoloader {
private string $appPath;
private string $libPath;
public function __construct($basedir)
{
$this->appPath = $basedir.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR;
$this->libPath = $basedir.DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR;
}
public function load($className) {
$parts = explode('\\', $className);
$len = count($parts);
$res = $parts[0] === 'Mcp' ? $this->appPath : $this->libPath;
for ($i = 1; $i < $len - 1; $i++) {
$res = $res.strtolower($parts[$i]).DIRECTORY_SEPARATOR;
}
require $res.$parts[$len - 1].'.php';
}
}