laravel.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php namespace Laravel;
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Bootstrap The Framework Core
  5. |--------------------------------------------------------------------------
  6. |
  7. | By including this file, the core of the framework will be setup which
  8. | includes the class auto-loader, and the registration of any bundles.
  9. | Basically, once this file has been included, the entire framework
  10. | may be used by the developer.
  11. |
  12. */
  13. require 'core.php';
  14. /*
  15. |--------------------------------------------------------------------------
  16. | Setup Error & Exception Handling
  17. |--------------------------------------------------------------------------
  18. |
  19. | Next we'll register custom handlers for all errors and exceptions so we
  20. | can display a clean error message for all errors, as well as do any
  21. | custom error logging that may be setup by the developer.
  22. |
  23. */
  24. set_exception_handler(function($e)
  25. {
  26. Error::exception($e);
  27. });
  28. set_error_handler(function($code, $error, $file, $line)
  29. {
  30. Error::native($code, $error, $file, $line);
  31. });
  32. register_shutdown_function(function()
  33. {
  34. Error::shutdown();
  35. });
  36. /*
  37. |--------------------------------------------------------------------------
  38. | Report All Errors
  39. |--------------------------------------------------------------------------
  40. |
  41. | By setting error reporting to -1, we essentially force PHP to report
  42. | every error, and this is guranteed to show every error on future
  43. | releases of PHP. This allows everything to be fixed early!
  44. |
  45. */
  46. error_reporting(-1);
  47. /*
  48. |--------------------------------------------------------------------------
  49. | Magic Quotes Strip Slashes
  50. |--------------------------------------------------------------------------
  51. |
  52. | Even though "Magic Quotes" are deprecated in PHP 5.3.x, they may still
  53. | be enabled on the server. To account for this, we will strip slashes
  54. | on all input arrays if magic quotes are enabled for the server.
  55. |
  56. */
  57. if (magic_quotes())
  58. {
  59. $magics = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  60. foreach ($magics as &$magic)
  61. {
  62. $magic = array_strip_slashes($magic);
  63. }
  64. }
  65. /*
  66. |--------------------------------------------------------------------------
  67. | Sniff The Input For The Request
  68. |--------------------------------------------------------------------------
  69. |
  70. | Next we'll gather the input to the application based on the global input
  71. | variables for the current request. The input will be gathered based on
  72. | the current request method and will be set on the Input manager class
  73. | as a simple static $input property which can be easily accessed.
  74. |
  75. */
  76. $input = array();
  77. switch (Request::method())
  78. {
  79. case 'GET':
  80. $input = $_GET;
  81. break;
  82. case 'POST':
  83. $input = $_POST;
  84. break;
  85. default:
  86. if (Request::spoofed())
  87. {
  88. $input = $_POST;
  89. }
  90. else
  91. {
  92. parse_str(file_get_contents('php://input'), $input);
  93. if (magic_quotes()) $input = array_strip_slashes($input);
  94. }
  95. }
  96. /*
  97. |--------------------------------------------------------------------------
  98. | Remove The Spoofer Input
  99. |--------------------------------------------------------------------------
  100. |
  101. | The spoofed request method is removed from the input so it is not in
  102. | the Input::all() or Input::get() results. Leaving it in the array
  103. | could cause unexpected results since the developer won't be
  104. | expecting it to be present.
  105. |
  106. */
  107. unset($input[Request::spoofer]);
  108. Input::$input = $input;
  109. /*
  110. |--------------------------------------------------------------------------
  111. | Start The Application Bundle
  112. |--------------------------------------------------------------------------
  113. |
  114. | The application "bundle" is the default bundle for the installation and
  115. | we'll fire it up first. In this bundle's bootstrap, more configuration
  116. | will take place and the developer can hook into some of the core
  117. | framework events such as the configuration loader.
  118. |
  119. */
  120. Bundle::start(DEFAULT_BUNDLE);
  121. /*
  122. |--------------------------------------------------------------------------
  123. | Auto-Start Other Bundles
  124. |--------------------------------------------------------------------------
  125. |
  126. | Bundles that are used throughout the application may be auto-started
  127. | so they are immediately available on every request without needing
  128. | to explicitly start them within the application.
  129. |
  130. */
  131. foreach (Bundle::$bundles as $bundle => $config)
  132. {
  133. if ($config['auto']) Bundle::start($bundle);
  134. }
  135. /*
  136. |--------------------------------------------------------------------------
  137. | Register The Catch-All Route
  138. |--------------------------------------------------------------------------
  139. |
  140. | This route will catch all requests that do not hit another route in
  141. | the application, and will raise the 404 error event so the error
  142. | can be handled by the developer in their 404 event listener.
  143. |
  144. */
  145. Routing\Router::register('*', '(:all)', function()
  146. {
  147. return Event::first('404');
  148. });
  149. /*
  150. |--------------------------------------------------------------------------
  151. | Route The Incoming Request
  152. |--------------------------------------------------------------------------
  153. |
  154. | Phew! We can finally route the request to the appropriate route and
  155. | execute the route to get the response. This will give an instance
  156. | of the Response object that we can send back to the browser
  157. |
  158. */
  159. $uri = URI::current();
  160. Request::$route = Routing\Router::route(Request::method(), $uri);
  161. $response = Request::$route->call();
  162. /*
  163. |--------------------------------------------------------------------------
  164. | Persist The Session To Storage
  165. |--------------------------------------------------------------------------
  166. |
  167. | If a session driver has been configured, we will save the session to
  168. | storage so it is avaiable for the next request. This will also set
  169. | the session cookie in the cookie jar to be sent to the user.
  170. |
  171. */
  172. if (Config::get('session.driver') !== '')
  173. {
  174. Session::save();
  175. }
  176. /*
  177. |--------------------------------------------------------------------------
  178. | Let's Eat Cookies
  179. |--------------------------------------------------------------------------
  180. |
  181. | All cookies set during the request are actually stored in a cookie jar
  182. | until the end of the request so they can be expected by unit tests or
  183. | the developer. Here, we'll push them out to the browser.
  184. |
  185. */
  186. Cookie::send();
  187. /*
  188. |--------------------------------------------------------------------------
  189. | Send The Response To The Browser
  190. |--------------------------------------------------------------------------
  191. |
  192. | We'll send the response back to the browser here. This method will also
  193. | send all of the response headers to the browser as well as the string
  194. | content of the Response. This should make the view available to the
  195. | browser and show something pretty to the user.
  196. |
  197. */
  198. $response->send();
  199. /*
  200. |--------------------------------------------------------------------------
  201. | And We're Done!
  202. |--------------------------------------------------------------------------
  203. |
  204. | Raise the "done" event so extra output can be attached to the response
  205. | This allows the adding of debug toolbars, etc. to the view, or may be
  206. | used to do some kind of logging by the application.
  207. |
  208. */
  209. Event::fire('laravel.done');