From 024a140609d659e1a4ff1d8bef896447b97ec4e3 Mon Sep 17 00:00:00 2001 From: Anonymous Contributor Date: Tue, 29 Aug 2023 13:53:32 +0200 Subject: [PATCH] Add simple PSR-4 autoloader --- app/autoload.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/autoload.php diff --git a/app/autoload.php b/app/autoload.php new file mode 100644 index 0000000..40efb79 --- /dev/null +++ b/app/autoload.php @@ -0,0 +1,27 @@ +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'; + } + +}