You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
878B

  1. <?php
  2. /**
  3. * Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0)
  4. * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
  5. *
  6. * Code inspired from the SplClassLoader RFC
  7. * @see https://wiki.php.net/rfc/splclassloader#example_implementation
  8. */
  9. spl_autoload_register(function ($className) {
  10. $className = ltrim($className, '\\');
  11. $fileName = '';
  12. if ($lastNsPos = strripos($className, '\\')) {
  13. $namespace = substr($className, 0, $lastNsPos);
  14. $className = substr($className, $lastNsPos + 1);
  15. $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
  16. }
  17. $fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
  18. if (file_exists($fileName)) {
  19. require $fileName;
  20. return true;
  21. }
  22. return false;
  23. });