Drupal investigation

MapClassLoader.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\ClassLoader;
  11. /**
  12. * A class loader that uses a mapping file to look up paths.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class MapClassLoader
  17. {
  18. private $map = array();
  19. /**
  20. * Constructor.
  21. *
  22. * @param array $map A map where keys are classes and values the absolute file path
  23. */
  24. public function __construct(array $map)
  25. {
  26. $this->map = $map;
  27. }
  28. /**
  29. * Registers this instance as an autoloader.
  30. *
  31. * @param bool $prepend Whether to prepend the autoloader or not
  32. */
  33. public function register($prepend = false)
  34. {
  35. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  36. }
  37. /**
  38. * Loads the given class or interface.
  39. *
  40. * @param string $class The name of the class
  41. */
  42. public function loadClass($class)
  43. {
  44. if (isset($this->map[$class])) {
  45. require $this->map[$class];
  46. }
  47. }
  48. /**
  49. * Finds the path to the file where the class is defined.
  50. *
  51. * @param string $class The name of the class
  52. *
  53. * @return string|null The path, if found
  54. */
  55. public function findFile($class)
  56. {
  57. if (isset($this->map[$class])) {
  58. return $this->map[$class];
  59. }
  60. }
  61. }