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.

63 lines
1.6 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Load
  7. * @since 2010-02-24
  8. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class Load
  12. {
  13. static protected $file;
  14. static protected $autoload;
  15. static public function setAutoloadFrom($file)
  16. {
  17. self::$file = $file;
  18. if (!file_exists(self::$file)) {
  19. self::buildAutoload();
  20. }
  21. self::$autoload = require(self::$file);
  22. }
  23. static public function autoload($class)
  24. {
  25. if (isset(self::$autoload[$class])) {
  26. require(PATH . self::$autoload[$class]);
  27. return;
  28. }
  29. if (defined('DEBUG') && DEBUG == true) {
  30. if (!isset(self::$autoload[$class])) {
  31. self::buildAutoload();
  32. }
  33. if (isset(self::$autoload[$class])) {
  34. require(PATH . self::$autoload[$class]);
  35. }
  36. }
  37. }
  38. static public function getFilePath($class)
  39. {
  40. return self::$autoload[$class];
  41. }
  42. static protected function buildAutoload()
  43. {
  44. ignore_user_abort(true);
  45. $dir = dirname(self::$file);
  46. if (!file_exists($dir) && !mkdir($dir)) {
  47. trigger_error('Can\'t create directory: "' . $dir . '"', E_USER_ERROR);
  48. }
  49. $scan = array(PATH . '/lib', PATH . '/' . APP . '/src');
  50. require_once(PATH . '/lib/core/util/AutoloadBuilder.php');
  51. $builder = new AutoloadBuilder(self::$file, $scan);
  52. $builder->build();
  53. ignore_user_abort(false);
  54. }
  55. }