Autoloader.php 699 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace GatewayWorker\Lib;
  3. class Autoloader
  4. {
  5. protected static $_rootPath = '';
  6. public static function setRootPath($root_path)
  7. {
  8. self::$_rootPath = $root_path;
  9. spl_autoload_register('\GatewayWorker\Lib\Autoloader::loadByNamespace');
  10. }
  11. public static function loadByNamespace($name)
  12. {
  13. $class_path = str_replace('\\', DIRECTORY_SEPARATOR ,$name);
  14. $class_file = self::$_rootPath . '/' . $class_path.'.php';
  15. if(is_file($class_file))
  16. {
  17. require_once($class_file);
  18. if(class_exists($name, false))
  19. {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. }