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.

79 lines
2.1 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 protected $exclude = array('/.git', '/lib/core/tests', '/lib/core/.git');
  16. /**
  17. * Add exclude path for autoload. Should be called before setAutoloadFrom
  18. * @static
  19. * @param array $exclude list of relative path (from project root)
  20. * @return void
  21. */
  22. static public function setExclude($exclude = array())
  23. {
  24. if(!is_array($exclude)) {
  25. $exclude = array($exclude);
  26. }
  27. self::$exclude = array_merge(self::$exclude, $exclude);
  28. }
  29. static public function setAutoloadFrom($file)
  30. {
  31. self::$file = $file;
  32. if (!file_exists(self::$file)) {
  33. self::buildAutoload();
  34. }
  35. self::$autoload = require(self::$file);
  36. }
  37. static public function autoload($class)
  38. {
  39. if (isset(self::$autoload[$class])) {
  40. require(PATH . self::$autoload[$class]);
  41. return;
  42. }
  43. if (defined('DEBUG') && DEBUG == true) {
  44. if (!isset(self::$autoload[$class])) {
  45. self::buildAutoload();
  46. }
  47. if (isset(self::$autoload[$class])) {
  48. require(PATH . self::$autoload[$class]);
  49. }
  50. }
  51. }
  52. static public function getFilePath($class)
  53. {
  54. return self::$autoload[$class];
  55. }
  56. static protected function buildAutoload()
  57. {
  58. ignore_user_abort(true);
  59. $dir = dirname(self::$file);
  60. if (!file_exists($dir) && !mkdir($dir)) {
  61. trigger_error('Can\'t create directory: "' . $dir . '"', E_USER_ERROR);
  62. }
  63. $scan = array(PATH . '/' . APP . '/src', PATH . '/lib');
  64. require_once(PATH . '/lib/core/util/AutoloadBuilder.php');
  65. $builder = new AutoloadBuilder(self::$file, $scan, self::$exclude);
  66. $builder->build();
  67. ignore_user_abort(false);
  68. }
  69. }