Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2. $rootDir = __DIR__.'/classes/';
  3.  
  4. $autoload = function($className) use($rootDir){
  5.  
  6. $fileName = '';
  7. if($lastNameSpacePosition = strpos($className,'\\')){
  8. $namespace = substr($className, 0,$lastNameSpacePosition);
  9. $className = substr($className,$lastNameSpacePosition+1);
  10. $fileName = str_replace('\\',DIRECTORY_SEPARATOR,$namespace).DIRECTORY_SEPARATOR;
  11. }
  12. $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className);
  13. if(is_file($rootDir.$fileName.'.php')){
  14. require_once $rootDir.$fileName.'.php';
  15. }
  16. };
  17.  
  18. spl_autoload_register($autoload);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement