laravel.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. | Create The HttpFoundation Request
  68. |--------------------------------------------------------------------------
  69. |
  70. | Laravel uses the HttpFoundation Symfony component to handle the request
  71. | and response functionality for the framework. This allows us to not
  72. | worry about that boilerplate code and focus on what matters.
  73. |
  74. */
  75. use Symfony\Component\HttpFoundation\LaravelRequest as RequestFoundation;
  76. Request::$foundation = RequestFoundation::createFromGlobals();
  77. /*
  78. |--------------------------------------------------------------------------
  79. | Start The Application Bundle
  80. |--------------------------------------------------------------------------
  81. |
  82. | The application "bundle" is the default bundle for the installation and
  83. | we'll fire it up first. In this bundle's bootstrap, more configuration
  84. | will take place and the developer can hook into some of the core
  85. | framework events such as the configuration loader.
  86. |
  87. */
  88. Bundle::start(DEFAULT_BUNDLE);
  89. /*
  90. |--------------------------------------------------------------------------
  91. | Auto-Start Other Bundles
  92. |--------------------------------------------------------------------------
  93. |
  94. | Bundles that are used throughout the application may be auto-started
  95. | so they are immediately available on every request without needing
  96. | to explicitly start them within the application.
  97. |
  98. */
  99. foreach (Bundle::$bundles as $bundle => $config)
  100. {
  101. if ($config['auto']) Bundle::start($bundle);
  102. }
  103. /*
  104. |--------------------------------------------------------------------------
  105. | Register The Catch-All Route
  106. |--------------------------------------------------------------------------
  107. |
  108. | This route will catch all requests that do not hit another route in
  109. | the application, and will raise the 404 error event so the error
  110. | can be handled by the developer in their 404 event listener.
  111. |
  112. */
  113. Routing\Router::register('*', '(:all)', function()
  114. {
  115. return Event::first('404');
  116. });
  117. /*
  118. |--------------------------------------------------------------------------
  119. | Route The Incoming Request
  120. |--------------------------------------------------------------------------
  121. |
  122. | Phew! We can finally route the request to the appropriate route and
  123. | execute the route to get the response. This will give an instance
  124. | of the Response object that we can send back to the browser
  125. |
  126. */
  127. $uri = URI::current();
  128. Request::$route = Routing\Router::route(Request::method(), $uri);
  129. $response = Request::$route->call();
  130. /*
  131. |--------------------------------------------------------------------------
  132. | Persist The Session To Storage
  133. |--------------------------------------------------------------------------
  134. |
  135. | If a session driver has been configured, we will save the session to
  136. | storage so it is avaiable for the next request. This will also set
  137. | the session cookie in the cookie jar to be sent to the user.
  138. |
  139. */
  140. if (Config::get('session.driver') !== '')
  141. {
  142. Session::save();
  143. }
  144. /*
  145. |--------------------------------------------------------------------------
  146. | Send The Response To The Browser
  147. |--------------------------------------------------------------------------
  148. |
  149. | We'll send the response back to the browser here. This method will also
  150. | send all of the response headers to the browser as well as the string
  151. | content of the Response. This should make the view available to the
  152. | browser and show something pretty to the user.
  153. |
  154. */
  155. $response->send();
  156. /*
  157. |--------------------------------------------------------------------------
  158. | And We're Done!
  159. |--------------------------------------------------------------------------
  160. |
  161. | Raise the "done" event so extra output can be attached to the response
  162. | This allows the adding of debug toolbars, etc. to the view, or may be
  163. | used to do some kind of logging by the application.
  164. |
  165. */
  166. Event::fire('laravel.done');