loader.php 894 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php namespace Laravel;
  2. class Loader {
  3. /**
  4. * The paths that will be searched by the loader.
  5. *
  6. * @var array
  7. */
  8. public $paths;
  9. /**
  10. * The class aliases defined for the application.
  11. *
  12. * @var array
  13. */
  14. public $aliases;
  15. /**
  16. * Create a new class loader instance.
  17. *
  18. * @param array $paths
  19. * @param array $aliases
  20. * @return void
  21. */
  22. public function __construct($paths, $aliases)
  23. {
  24. $this->paths = $paths;
  25. $this->aliases = $aliases;
  26. }
  27. /**
  28. * Load the file for a given class.
  29. *
  30. * @param string $class
  31. * @return void
  32. */
  33. public function load($class)
  34. {
  35. $file = strtolower(str_replace('\\', '/', $class));
  36. if (array_key_exists($class, $this->aliases)) return class_alias($this->aliases[$class], $class);
  37. foreach ($this->paths as $path)
  38. {
  39. if (file_exists($path = $path.$file.EXT))
  40. {
  41. require_once $path;
  42. return;
  43. }
  44. }
  45. }
  46. }