Last active
June 27, 2019 10:41
-
-
Save inhere/dba21990e370f82eb0241182c4c997f5 to your computer and use it in GitHub Desktop.
quick add an pacakge autoloader for php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$libDir = __DIR__ . '/'; | |
$npMap = [ | |
'SwoftTool\\' => $libDir, | |
// 'Inhere\\ValidateTest\\' => $libDir . '/test/', | |
]; | |
spl_autoload_register(function ($class) use ($npMap) { | |
foreach ($npMap as $np => $dir) { | |
if (strpos($class, $np) !== 0) { | |
continue; | |
} | |
$file = $dir . str_replace('\\', '/', substr($class, strlen($np))) . '.php'; | |
if (file_exists($file)) { | |
include $file; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment