core.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php namespace Laravel;
  2. require 'constants.php';
  3. /**
  4. * Load the classes that can't be resolved through the auto-loader.
  5. * These are typically classes that are used by the auto-loader or
  6. * configuration classes, and therefore cannot be auto-loaded.
  7. */
  8. require SYS_PATH.'arr'.EXT;
  9. require SYS_PATH.'config'.EXT;
  10. /**
  11. * Load some core configuration files by default so we don't have to
  12. * let them fall through the Config parser. This will allow us to
  13. * load these files faster for each request.
  14. */
  15. Config::load('application');
  16. Config::load('container');
  17. Config::load('session');
  18. /**
  19. * Bootstrap the application inversion of control (IoC) container.
  20. * The container provides the convenient resolution of objects and
  21. * their dependencies, allowing for flexibility and testability
  22. * within the framework and application.
  23. */
  24. require SYS_PATH.'container'.EXT;
  25. $container = new Container(Config::$items['container']);
  26. IoC::$container = $container;
  27. unset($container);
  28. /**
  29. * Register the application auto-loader. The auto-loader closure
  30. * is responsible for the lazy-loading of all of the Laravel core
  31. * classes, as well as the developer created libraries and models.
  32. */
  33. $aliases = Config::$items['application']['aliases'];
  34. spl_autoload_register(function($class) use ($aliases)
  35. {
  36. if (array_key_exists($class, $aliases))
  37. {
  38. return class_alias($aliases[$class], $class);
  39. }
  40. $file = strtolower(str_replace('\\', '/', $class));
  41. foreach (array(BASE_PATH, MODEL_PATH, LIBRARY_PATH) as $path)
  42. {
  43. if (file_exists($path = $path.$file.EXT))
  44. {
  45. require_once $path;
  46. return;
  47. }
  48. }
  49. });
  50. unset($aliases);
  51. /**
  52. * Define a few convenient global functions.
  53. */
  54. function e($value)
  55. {
  56. return HTML::entities($value);
  57. }
  58. function __($key, $replacements = array(), $language = null)
  59. {
  60. return Lang::line($key, $replacements, $language);
  61. }