core.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php namespace Laravel;
  2. define('APP_PATH', realpath($application).'/');
  3. define('BASE_PATH', realpath(str_replace('laravel', '', $laravel)).'/');
  4. define('PACKAGE_PATH', realpath($packages).'/');
  5. define('PUBLIC_PATH', realpath($public).'/');
  6. define('STORAGE_PATH', realpath($storage).'/');
  7. define('SYS_PATH', realpath($laravel).'/');
  8. unset($laravel, $application, $config, $packages, $public, $storage);
  9. define('CACHE_PATH', STORAGE_PATH.'cache/');
  10. define('CONFIG_PATH', APP_PATH.'config/');
  11. define('CONTROLLER_PATH', APP_PATH.'controllers/');
  12. define('DATABASE_PATH', STORAGE_PATH.'database/');
  13. define('LANG_PATH', APP_PATH.'language/');
  14. define('LIBRARY_PATH', APP_PATH.'libraries/');
  15. define('MODEL_PATH', APP_PATH.'models/');
  16. define('ROUTE_PATH', APP_PATH.'routes/');
  17. define('SESSION_PATH', STORAGE_PATH.'sessions/');
  18. define('SYS_CONFIG_PATH', SYS_PATH.'config/');
  19. define('SYS_LANG_PATH', SYS_PATH.'language/');
  20. define('SYS_VIEW_PATH', SYS_PATH.'views/');
  21. define('VIEW_PATH', APP_PATH.'views/');
  22. define('EXT', '.php');
  23. define('BLADE_EXT', '.blade.php');
  24. /**
  25. * Load the classes that can't be resolved through the auto-loader.
  26. * These are typically classes that are used by the auto-loader or
  27. * configuration classes, and therefore cannot be auto-loaded.
  28. */
  29. //require SYS_PATH.'facades'.EXT;
  30. require SYS_PATH.'config'.EXT;
  31. require SYS_PATH.'loader'.EXT;
  32. require SYS_PATH.'arr'.EXT;
  33. /**
  34. * If a Laravel environment has been specified on the server, we will
  35. * add a path to the configuration manager for the environment.
  36. */
  37. if (isset($_SERVER['LARAVEL_ENV']))
  38. {
  39. define('ENV_CONFIG_PATH', CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/');
  40. Config::glance(ENV_CONFIG_PATH);
  41. }
  42. /**
  43. * Load some core configuration files by default so we don't have to
  44. * let them fall through the Config loader. This will allow us to
  45. * load these files faster for each request.
  46. */
  47. foreach (array('application', 'session') as $file)
  48. {
  49. $config = require CONFIG_PATH.$file.EXT;
  50. if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = ENV_CONFIG_PATH.$file.EXT))
  51. {
  52. $config = array_merge($config, require $path);
  53. }
  54. Config::$items[$file] = $config;
  55. }
  56. /**
  57. * Load the container configuration into the Config class. We load
  58. * this file manually to avoid the overhead of Config::load.
  59. */
  60. Config::$items['container'] = require SYS_CONFIG_PATH.'container'.EXT;
  61. if (file_exists($path = CONFIG_PATH.'container'.EXT))
  62. {
  63. Config::$items['container'] = array_merge(Config::$items['container'], require $path);
  64. }
  65. if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = ENV_CONFIG_PATH.'container'.EXT))
  66. {
  67. Config::$items['container'] = array_merge(Config::$items['container'], require $path);
  68. }
  69. /**
  70. * Bootstrap the application inversion of control (IoC) container.
  71. * The container provides the convenient resolution of objects and
  72. * their dependencies, allowing for flexibility and testability
  73. * within the framework and application.
  74. */
  75. require SYS_PATH.'container'.EXT;
  76. $container = new Container(Config::$items['container']);
  77. IoC::$container = $container;
  78. unset($config, $container);
  79. /**
  80. * Register the application auto-loader. The auto-loader is responsible
  81. * for the lazy-loading of all of the Laravel core classes, as well as
  82. * the developer created libraries and models.
  83. */
  84. spl_autoload_register(array('Laravel\\Loader', 'load'));
  85. Loader::$aliases = Config::$items['application']['aliases'];
  86. /**
  87. * Define a few convenient global functions.
  88. */
  89. function e($value)
  90. {
  91. return HTML::entities($value);
  92. }
  93. function __($key, $replacements = array(), $language = null)
  94. {
  95. return Lang::line($key, $replacements, $language);
  96. }