laravel.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. | Start The Application Bundle
  50. |--------------------------------------------------------------------------
  51. |
  52. | The application "bundle" is the default bundle for the installation and
  53. | we'll fire it up first. In this bundle's bootstrap, more configuration
  54. | will take place and the developer can hook into some of the core
  55. | framework events such as the configuration loader.
  56. |
  57. */
  58. Bundle::start(DEFAULT_BUNDLE);
  59. /*
  60. |--------------------------------------------------------------------------
  61. | Auto-Start Other Bundles
  62. |--------------------------------------------------------------------------
  63. |
  64. | Bundles that are used throughout the application may be auto-started
  65. | so they are immediately available on every request without needing
  66. | to explicitly start them within the application.
  67. |
  68. */
  69. foreach (Bundle::$bundles as $bundle => $config)
  70. {
  71. if ($config['auto']) Bundle::start($bundle);
  72. }
  73. /*
  74. |--------------------------------------------------------------------------
  75. | Register The Catch-All Route
  76. |--------------------------------------------------------------------------
  77. |
  78. | This route will catch all requests that do not hit another route in
  79. | the application, and will raise the 404 error event so the error
  80. | can be handled by the developer in their 404 event listener.
  81. |
  82. */
  83. Routing\Router::register('*', '(:all)', function()
  84. {
  85. return Event::first('404');
  86. });
  87. /*
  88. |--------------------------------------------------------------------------
  89. | Route The Incoming Request
  90. |--------------------------------------------------------------------------
  91. |
  92. | Phew! We can finally route the request to the appropriate route and
  93. | execute the route to get the response. This will give an instance
  94. | of the Response object that we can send back to the browser
  95. |
  96. */
  97. $uri = URI::current();
  98. Request::$route = Routing\Router::route(Request::method(), $uri);
  99. $response = Request::$route->call();
  100. /*
  101. |--------------------------------------------------------------------------
  102. | Persist The Session To Storage
  103. |--------------------------------------------------------------------------
  104. |
  105. | If a session driver has been configured, we will save the session to
  106. | storage so it is avaiable for the next request. This will also set
  107. | the session cookie in the cookie jar to be sent to the user.
  108. |
  109. */
  110. if (Config::get('session.driver') !== '')
  111. {
  112. Session::save();
  113. }
  114. /*
  115. |--------------------------------------------------------------------------
  116. | Send The Response To The Browser
  117. |--------------------------------------------------------------------------
  118. |
  119. | We'll send the response back to the browser here. This method will also
  120. | send all of the response headers to the browser as well as the string
  121. | content of the Response. This should make the view available to the
  122. | browser and show something pretty to the user.
  123. |
  124. */
  125. $response->send();
  126. /*
  127. |--------------------------------------------------------------------------
  128. | And We're Done!
  129. |--------------------------------------------------------------------------
  130. |
  131. | Raise the "done" event so extra output can be attached to the response
  132. | This allows the adding of debug toolbars, etc. to the view, or may be
  133. | used to do some kind of logging by the application.
  134. |
  135. */
  136. Event::fire('laravel.done', array($response));