Add simple PSR-4 autoloader
							parent
							
								
									6c22684b2f
								
							
						
					
					
						commit
						024a140609
					
				|  | @ -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'; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	 Anonymous Contributor
						Anonymous Contributor