morrisonlevi

autoload.php

Oct 28th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class FileNotFoundException extends Exception{}
  2.  
  3. function __autoload($ClassName) {
  4.     $classPath = join(DIRECTORY_SEPARATOR, explode('\\', trim($ClassName,'\\')));
  5.     $extentions = explode(',', spl_autoload_extensions());
  6.    
  7.     $includePaths = explode(PATH_SEPARATOR, get_include_path());
  8.    
  9.     foreach ($includePaths as $path) {
  10.         foreach ($extentions as $ext):
  11.             $file = $path.DIRECTORY_SEPARATOR.$classPath.$ext;
  12. //          echo "Trying $file . . .\n";
  13.             if (is_file($file)) {
  14. //              echo "Found $file . . .\n\n";
  15.                 require $classPath.$ext;
  16.                 return;
  17.             }
  18.         endforeach;
  19.     }
  20.    
  21.     throw new FileNotFoundException("Couldn't find $classPath using extentions: (". join('|', $extentions).').');
  22. }
  23. spl_autoload_extensions('.class.php,.php,.enum.php');
  24. spl_autoload_register('__autoload', true);
  25.  
Advertisement
Add Comment
Please, Sign In to add comment