diff --git a/autoload.php b/autoload.php new file mode 100644 index 0000000..8ed2144 --- /dev/null +++ b/autoload.php @@ -0,0 +1,30 @@ + $classpaths) { + if (!is_array($classpaths)) { + $classpaths = array($classpaths); + } + spl_autoload_register(function ($classname) use ($namespace, $classpaths, $dir) { + // Check if the namespace matches the class we are looking for + if (preg_match("#^".preg_quote($namespace)."#", $classname)) { + // Remove the namespace from the file path since it's psr4 + $classname = str_replace($namespace, "", $classname); + $filename = preg_replace("#\\\\#", "/", $classname).".php"; + foreach ($classpaths as $classpath) { + $fullpath = $dir."/".$classpath."/$filename"; + if (file_exists($fullpath)) { + include_once $fullpath; + } + } + } + }); + } +} + +loadPackage(__DIR__."/");