<?php
class AutoLoad
{
private $vendorPath;
public static function start($rootPath, $classname){
try{
$reflectionClass = new ReflectionClass($classname);
$getInstanceMethod = $reflectionClass->getMethod('start');
$getInstanceMethod->invokeArgs(null, [$rootPath]);
}catch (Exception $e){
echo $e->getTraceAsString();
}
return ;
}
public static function load($vendorPath){
(new self())->register($vendorPath);
}
public function register($vendorPath){
$this->vendorPath = $vendorPath;
$this->autoRegister();
}
private function autoRegister(){
spl_autoload_register( [$this, 'useNameSpace']);
}
private function useNameSpace($class) {
include $this->vendorPath . "/" . str_replace('\\','/', $class).".php";
}
}