PHP Autoload-Klassen aus verschiedenen Verzeichnissen

Ich habe diesen Code gefunden, der alle Klassen innerhalb eines einzelnen Verzeichnisses automatisch lädt, und er funktioniert ziemlich gut. Ich möchte es ein wenig erweitern können, um Klassen aus verschiedenen Pfaden (Verzeichnissen) zu laden. Hier ist der Code:

  define('PATH', realpath(dirname(__file__)) . '/classes') . '/';
  define('DS', DIRECTORY_SEPARATOR);

  class Autoloader
  {
      private static $__loader;


      private function __construct()
      {
          spl_autoload_register(array($this, 'autoLoad'));
      }


      public static function init()
      {
          if (self::$__loader == null) {
              self::$__loader = new self();
          }

          return self::$__loader;
      }


      public function autoLoad($class)
      {
          $exts = array('.class.php');

          spl_autoload_extensions("'" . implode(',', $exts) . "'");
          set_include_path(get_include_path() . PATH_SEPARATOR . PATH);

          foreach ($exts as $ext) {
              if (is_readable($path = BASE . strtolower($class . $ext))) {
                  require_once $path;
                  return true;
              }
          }
          self::recursiveAutoLoad($class, PATH);
      }

      private static function recursiveAutoLoad($class, $path)
      {
          if (is_dir($path)) {
              if (($handle = opendir($path)) !== false) {
                  while (($resource = readdir($handle)) !== false) {
                      if (($resource == '..') or ($resource == '.')) {
                          continue;
                      }

                      if (is_dir($dir = $path . DS . $resource)) {
                          continue;
                      } else
                          if (is_readable($file = $path . DS . $resource)) {
                              require_once $file;
                          }
                  }
                  closedir($handle);
              }
          }
      }
  }

then in runt in meiner index.php Datei wie:

Autoloader::init();

Ich benutze PHP 5.6

Antworten auf die Frage(2)

Ihre Antwort auf die Frage