laravel.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. require_once path('sys').'error'.EXT;
  27. Error::exception($e);
  28. });
  29. set_error_handler(function($code, $error, $file, $line)
  30. {
  31. require_once path('sys').'error'.EXT;
  32. Error::native($code, $error, $file, $line);
  33. });
  34. register_shutdown_function(function()
  35. {
  36. require_once path('sys').'error'.EXT;
  37. Error::shutdown();
  38. });
  39. /*
  40. |--------------------------------------------------------------------------
  41. | Report All Errors
  42. |--------------------------------------------------------------------------
  43. |
  44. | By setting error reporting to -1, we essentially force PHP to report
  45. | every error, and this is guranteed to show every error on future
  46. | releases of PHP. This allows everything to be fixed early!
  47. |
  48. */
  49. error_reporting(-1);
  50. /*
  51. |--------------------------------------------------------------------------
  52. | Start The Application Bundle
  53. |--------------------------------------------------------------------------
  54. |
  55. | The application "bundle" is the default bundle for the installation and
  56. | we'll fire it up first. In this bundle's bootstrap, more configuration
  57. | will take place and the developer can hook into some of the core
  58. | framework events such as the configuration loader.
  59. |
  60. */
  61. Bundle::start(DEFAULT_BUNDLE);
  62. /*
  63. |--------------------------------------------------------------------------
  64. | Auto-Start Other Bundles
  65. |--------------------------------------------------------------------------
  66. |
  67. | Bundles that are used throughout the application may be auto-started
  68. | so they are immediately available on every request without needing
  69. | to explicitly start them within the application.
  70. |
  71. */
  72. foreach (Bundle::$bundles as $bundle => $config)
  73. {
  74. if ($config['auto']) Bundle::start($bundle);
  75. }
  76. /*
  77. |--------------------------------------------------------------------------
  78. | Register The Catch-All Route
  79. |--------------------------------------------------------------------------
  80. |
  81. | This route will catch all requests that do not hit another route in
  82. | the application, and will raise the 404 error event so the error
  83. | can be handled by the developer in their 404 event listener.
  84. |
  85. */
  86. Routing\Router::register('*', '(:all)', function()
  87. {
  88. return Event::first('404');
  89. });
  90. /*
  91. |--------------------------------------------------------------------------
  92. | Route The Incoming Request
  93. |--------------------------------------------------------------------------
  94. |
  95. | Phew! We can finally route the request to the appropriate route and
  96. | execute the route to get the response. This will give an instance
  97. | of the Response object that we can send back to the browser
  98. |
  99. */
  100. $uri = URI::current();
  101. Request::$route = Routing\Router::route(Request::method(), $uri);
  102. $response = Request::$route->call();
  103. /*
  104. |--------------------------------------------------------------------------
  105. | "Render" The Response
  106. |--------------------------------------------------------------------------
  107. |
  108. | The render method evaluates the content of the response and converts it
  109. | to a string. This evaluates any views and sub-responses within the
  110. | content and sets the raw string result as the new response.
  111. |
  112. */
  113. $response->render();
  114. /*
  115. |--------------------------------------------------------------------------
  116. | Persist The Session To Storage
  117. |--------------------------------------------------------------------------
  118. |
  119. | If a session driver has been configured, we will save the session to
  120. | storage so it is avaiable for the next request. This will also set
  121. | the session cookie in the cookie jar to be sent to the user.
  122. |
  123. */
  124. if (Config::get('session.driver') !== '')
  125. {
  126. Session::save();
  127. }
  128. /*
  129. |--------------------------------------------------------------------------
  130. | Send The Response To The Browser
  131. |--------------------------------------------------------------------------
  132. |
  133. | We'll send the response back to the browser here. This method will also
  134. | send all of the response headers to the browser as well as the string
  135. | content of the Response. This should make the view available to the
  136. | browser and show something pretty to the user.
  137. |
  138. */
  139. $response->send();
  140. /*
  141. |--------------------------------------------------------------------------
  142. | And We're Done!
  143. |--------------------------------------------------------------------------
  144. |
  145. | Raise the "done" event so extra output can be attached to the response
  146. | This allows the adding of debug toolbars, etc. to the view, or may be
  147. | used to do some kind of logging by the application.
  148. |
  149. */
  150. Event::fire('laravel.done', array($response));