core.php 7.8 KB

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