core.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php namespace Laravel;
  2. /*
  3. |--------------------------------------------------------------------------
  4. | PHP Display Errors Configuration
  5. |--------------------------------------------------------------------------
  6. |
  7. | Register the constants used by the framework. These are things like file
  8. | extensions and other information that we want to be able to access with
  9. | just a simple constant.
  10. |
  11. */
  12. define('EXT', '.php');
  13. define('CRLF', "\r\n");
  14. define('DEFAULT_BUNDLE', 'application');
  15. define('MB_STRING', (int) function_exists('mb_get_info'));
  16. /*
  17. |--------------------------------------------------------------------------
  18. | Require Core Classes
  19. |--------------------------------------------------------------------------
  20. |
  21. | Here we will just load in the classes that are used for every request
  22. | or are used by the configuration class. It is quicker and simpler to
  23. | just manually load them in instead of using the auto-loader.
  24. |
  25. */
  26. require path('sys').'ioc'.EXT;
  27. require path('sys').'event'.EXT;
  28. require path('sys').'bundle'.EXT;
  29. require path('sys').'config'.EXT;
  30. require path('sys').'helpers'.EXT;
  31. require path('sys').'autoloader'.EXT;
  32. /*
  33. |--------------------------------------------------------------------------
  34. | Register The Framework Auto-Loader
  35. |--------------------------------------------------------------------------
  36. |
  37. | Next we'll register the Autoloader class on the SPL auto-loader stack
  38. | so it can lazy-load our class files as we need them. This class and
  39. | method will be called each time a class is needed but has not been
  40. | defined yet and will load the appropriate file.
  41. |
  42. */
  43. spl_autoload_register(array('Laravel\\Autoloader', 'load'));
  44. /*
  45. |--------------------------------------------------------------------------
  46. | Register The Laravel Namespace
  47. |--------------------------------------------------------------------------
  48. |
  49. | Register the "Laravel" namespace and its directory mapping so the class
  50. | loader can quickly load all of the core classes using PSR-0 style load
  51. | conventions throughout the "laravel" directory since all core classes
  52. | are namespaced into the "Laravel" namespace.
  53. |
  54. */
  55. Autoloader::namespaces(array('Laravel' => path('sys')));
  56. /*
  57. |--------------------------------------------------------------------------
  58. | Register Eloquent Mappings
  59. |--------------------------------------------------------------------------
  60. |
  61. | A few of the Eloquent ORM classes use a non PSR-0 naming standard so
  62. | we will just map them with hard-coded paths here since PSR-0 uses
  63. | underscores as directory hierarchy indicators.
  64. |
  65. */
  66. Autoloader::map(array(
  67. 'Laravel\\Database\\Eloquent\\Relationships\\Belongs_To'
  68. => path('sys').'database/eloquent/relationships/belongs_to'.EXT,
  69. 'Laravel\\Database\\Eloquent\\Relationships\\Has_Many'
  70. => path('sys').'database/eloquent/relationships/has_many'.EXT,
  71. 'Laravel\\Database\\Eloquent\\Relationships\\Has_Many_And_Belongs_To'
  72. => path('sys').'database/eloquent/relationships/has_many_and_belongs_to'.EXT,
  73. 'Laravel\\Database\\Eloquent\\Relationships\\Has_One'
  74. => path('sys').'database/eloquent/relationships/has_one'.EXT,
  75. 'Laravel\\Database\\Eloquent\\Relationships\\Has_One_Or_Many'
  76. => path('sys').'database/eloquent/relationships/has_one_or_many'.EXT,
  77. ));
  78. /*
  79. |--------------------------------------------------------------------------
  80. | Set The CLI Options Array
  81. |--------------------------------------------------------------------------
  82. |
  83. | If the current request is from the Artisan command-line interface, we
  84. | will parse the command line arguments and options and set them the
  85. | array of options in the $_SERVER global array for convenience.
  86. |
  87. */
  88. if (defined('STDIN'))
  89. {
  90. $console = CLI\Command::options($_SERVER['argv']);
  91. list($arguments, $options) = $console;
  92. $options = array_change_key_case($options, CASE_UPPER);
  93. $_SERVER['CLI'] = $options;
  94. }
  95. /*
  96. |--------------------------------------------------------------------------
  97. | Set The CLI Laravel Environment
  98. |--------------------------------------------------------------------------
  99. |
  100. | Next we'll set the LARAVEL_ENV variable if the current request is from
  101. | the Artisan command-line interface. Since the environment is often
  102. | specified within an Apache .htaccess file, we need to set it here
  103. | when the request is not coming through Apache.
  104. |
  105. */
  106. if (isset($_SERVER['CLI']['ENV']))
  107. {
  108. $_SERVER['LARAVEL_ENV'] = $_SERVER['CLI']['ENV'];
  109. }
  110. /*
  111. |--------------------------------------------------------------------------
  112. | Register The Laravel Bundles
  113. |--------------------------------------------------------------------------
  114. |
  115. | Finally we will register all of the bundles that have been defined for
  116. | the application. None of them will be started, yet but will be setup
  117. | so that they may be started by the develop at any time.
  118. |
  119. */
  120. $bundles = require path('app').'bundles'.EXT;
  121. foreach ($bundles as $bundle => $config)
  122. {
  123. Bundle::register($bundle, $config);
  124. }