Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. spl_autoload_register(function ($class) {
  2. $className = ltrim($class, '\\');
  3. if ($lastNsPos = strrpos($className, '\\')) {
  4. $namespace = substr($className, 0, $lastNsPos);
  5. $className = substr($className, $lastNsPos + 1);
  6. }
  7.  
  8. if(strpos($class, $namespace) === 0) {
  9. if(strpos($namespace, DIRECTORY_SEPARATOR) !== false) {
  10. $folder = strtolower(substr($namespace, strpos($namespace, DIRECTORY_SEPARATOR) + 1));
  11. $path = str_replace('/', DIRECTORY_SEPARATOR, str_replace('\\', DIRECTORY_SEPARATOR, __DIR__ . '/' . $folder . '/' . $className . '.php'));
  12. if (is_file($path) && is_readable($path)) {
  13. include_once $path;
  14. }
  15. }
  16. }
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement