core.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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('BLADE_EXT', '.blade.php');
  15. define('DEFAULT_BUNDLE', 'application');
  16. define('MB_STRING', (int) function_exists('mb_get_info'));
  17. /*
  18. |--------------------------------------------------------------------------
  19. | Require Core Classes
  20. |--------------------------------------------------------------------------
  21. |
  22. | Here we will just load in the classes that are used for every request
  23. | or are used by the configuration class. It is quicker and simpler to
  24. | just manually load them in instead of using the auto-loader.
  25. |
  26. */
  27. require path('sys').'ioc'.EXT;
  28. require path('sys').'event'.EXT;
  29. require path('sys').'bundle'.EXT;
  30. require path('sys').'config'.EXT;
  31. require path('sys').'helpers'.EXT;
  32. require path('sys').'autoloader'.EXT;
  33. /*
  34. |--------------------------------------------------------------------------
  35. | Register The Framework Auto-Loader
  36. |--------------------------------------------------------------------------
  37. |
  38. | Next we'll register the Autoloader class on the SPL auto-loader stack
  39. | so it can lazy-load our class files as we need them. This class and
  40. | method will be called each time a class is needed but has not been
  41. | defined yet and will load the appropriate file.
  42. |
  43. */
  44. spl_autoload_register(array('Laravel\\Autoloader', 'load'));
  45. /*
  46. |--------------------------------------------------------------------------
  47. | Register The Laravel Namespace
  48. |--------------------------------------------------------------------------
  49. |
  50. | Register the "Laravel" namespace and its directory mapping so the class
  51. | loader can quickly load all of the core classes using PSR-0 style load
  52. | conventions throughout the "laravel" directory since all core classes
  53. | are namespaced into the "Laravel" namespace.
  54. |
  55. */
  56. Autoloader::namespaces(array('Laravel' => path('sys')));
  57. /*
  58. |--------------------------------------------------------------------------
  59. | Register Eloquent Mappings
  60. |--------------------------------------------------------------------------
  61. |
  62. | A few of the Eloquent ORM classes use a non PSR-0 naming standard so
  63. | we will just map them with hard-coded paths here since PSR-0 uses
  64. | underscores as directory hierarchy indicators.
  65. |
  66. */
  67. Autoloader::map(array(
  68. 'Laravel\\Database\\Eloquent\\Relationships\\Belongs_To'
  69. => path('sys').'database/eloquent/relationships/belongs_to'.EXT,
  70. 'Laravel\\Database\\Eloquent\\Relationships\\Has_Many'
  71. => path('sys').'database/eloquent/relationships/has_many'.EXT,
  72. 'Laravel\\Database\\Eloquent\\Relationships\\Has_Many_And_Belongs_To'
  73. => path('sys').'database/eloquent/relationships/has_many_and_belongs_to'.EXT,
  74. 'Laravel\\Database\\Eloquent\\Relationships\\Has_One'
  75. => path('sys').'database/eloquent/relationships/has_one'.EXT,
  76. 'Laravel\\Database\\Eloquent\\Relationships\\Has_One_Or_Many'
  77. => path('sys').'database/eloquent/relationships/has_one_or_many'.EXT,
  78. ));
  79. /*
  80. |--------------------------------------------------------------------------
  81. | Register The Symfony Components
  82. |--------------------------------------------------------------------------
  83. |
  84. | Laravel makes use of the Symfony components where the situation is
  85. | applicable and it is possible to do so. This allows us to focus
  86. | on the parts of the framework that are unique and not re-do
  87. | plumbing code that others have written.
  88. |
  89. */
  90. Autoloader::namespaces(array(
  91. 'Symfony\Component\Console'
  92. => path('sys').'vendor/Symfony/Component/Console',
  93. 'Symfony\Component\HttpFoundation'
  94. => path('sys').'vendor/Symfony/Component/HttpFoundation',
  95. ));
  96. /*
  97. |--------------------------------------------------------------------------
  98. | Magic Quotes Strip Slashes
  99. |--------------------------------------------------------------------------
  100. |
  101. | Even though "Magic Quotes" are deprecated in PHP 5.3.x, they may still
  102. | be enabled on the server. To account for this, we will strip slashes
  103. | on all input arrays if magic quotes are enabled for the server.
  104. |
  105. */
  106. if (magic_quotes())
  107. {
  108. $magics = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  109. foreach ($magics as &$magic)
  110. {
  111. $magic = array_strip_slashes($magic);
  112. }
  113. }
  114. /*
  115. |--------------------------------------------------------------------------
  116. | Create The HttpFoundation Request
  117. |--------------------------------------------------------------------------
  118. |
  119. | Laravel uses the HttpFoundation Symfony component to handle the request
  120. | and response functionality for the framework. This allows us to not
  121. | worry about that boilerplate code and focus on what matters.
  122. |
  123. */
  124. use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
  125. Request::$foundation = RequestFoundation::createFromGlobals();
  126. /*
  127. |--------------------------------------------------------------------------
  128. | Determine The Application Environment
  129. |--------------------------------------------------------------------------
  130. |
  131. | Next we're ready to determine the application environment. This may be
  132. | set either via the command line options or via the mapping of URIs to
  133. | environments that lives in the "paths.php" file for the application
  134. | and is parsed. When determining the CLI environment, the "--env"
  135. | CLI option overrides the mapping in "paths.php".
  136. |
  137. */
  138. if (Request::cli())
  139. {
  140. $environment = get_cli_option('env');
  141. if ( ! isset($environment))
  142. {
  143. $environment = Request::detect_env($environments, gethostname());
  144. }
  145. }
  146. else
  147. {
  148. $root = Request::foundation()->getRootUrl();
  149. $environment = Request::detect_env($environments, $root);
  150. }
  151. /*
  152. |--------------------------------------------------------------------------
  153. | Set The Application Environment
  154. |--------------------------------------------------------------------------
  155. |
  156. | Once we have determined the application environment, we will set it on
  157. | the global server array of the HttpFoundation request. This makes it
  158. | available throughout the application, thought it is mainly only
  159. | used to determine which configuration files to merge in.
  160. |
  161. */
  162. if (isset($environment))
  163. {
  164. Request::set_env($environment);
  165. }
  166. /*
  167. |--------------------------------------------------------------------------
  168. | Set The CLI Options Array
  169. |--------------------------------------------------------------------------
  170. |
  171. | If the current request is from the Artisan command-line interface, we
  172. | will parse the command line arguments and options and set them the
  173. | array of options in the $_SERVER global array for convenience.
  174. |
  175. */
  176. if (defined('STDIN'))
  177. {
  178. $console = CLI\Command::options($_SERVER['argv']);
  179. list($arguments, $options) = $console;
  180. $options = array_change_key_case($options, CASE_UPPER);
  181. $_SERVER['CLI'] = $options;
  182. }
  183. /*
  184. |--------------------------------------------------------------------------
  185. | Register The Laravel Bundles
  186. |--------------------------------------------------------------------------
  187. |
  188. | Finally we will register all of the bundles that have been defined for
  189. | the application. None of them will be started yet, but will be setup
  190. | so that they may be started by the developer at any time.
  191. |
  192. */
  193. $bundles = require path('app').'bundles'.EXT;
  194. foreach ($bundles as $bundle => $config)
  195. {
  196. Bundle::register($bundle, $config);
  197. }