laravel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php namespace Laravel;
  2. /**
  3. * Bootstrap the core framework components like the IoC container,
  4. * configuration class, and the class auto-loader. Once this file
  5. * has run, the framework is essentially ready for use.
  6. */
  7. require 'bootstrap/core.php';
  8. /**
  9. * Register the framework error handling methods and set the
  10. * error_reporting levels. This file will register handlers
  11. * for exceptions, errors, and shutdown.
  12. */
  13. require SYS_PATH.'bootstrap/errors'.EXT;
  14. /**
  15. * Set the application's default timezone.
  16. */
  17. date_default_timezone_set(Config::get('application.timezone'));
  18. /**
  19. * Load the session and session manager instance. The session
  20. * payload will be registered in the IoC container as an instance
  21. * so it can be retrieved easily throughout the application.
  22. */
  23. if (Config::get('session.driver') !== '')
  24. {
  25. $session = $container->core('session.manager');
  26. $container->instance('laravel.session', $session->payload(Config::get('session')));
  27. }
  28. /**
  29. * Manually load some core classes that are used on every request
  30. * This allows to avoid using the loader for these classes.
  31. */
  32. require SYS_PATH.'uri'.EXT;
  33. require SYS_PATH.'request'.EXT;
  34. require SYS_PATH.'routing/route'.EXT;
  35. require SYS_PATH.'routing/router'.EXT;
  36. require SYS_PATH.'routing/loader'.EXT;
  37. require SYS_PATH.'routing/caller'.EXT;
  38. /**
  39. * Gather the input to the application for the current request.
  40. * The input will be gathered based on the current request method
  41. * and will be set on the Input manager.
  42. */
  43. $input = array();
  44. switch (Request::method())
  45. {
  46. case 'GET':
  47. $input = $_GET;
  48. break;
  49. case 'POST':
  50. $input = $_POST;
  51. break;
  52. case 'PUT':
  53. case 'DELETE':
  54. if (Request::spoofed())
  55. {
  56. $input = $_POST;
  57. }
  58. else
  59. {
  60. parse_str(file_get_contents('php://input'), $input);
  61. }
  62. }
  63. unset($input[Request::spoofer]);
  64. Input::set($input);
  65. /**
  66. * Route the request to the proper route in the application. If a
  67. * route is found, the route will be called with the current request
  68. * instance. If no route is found, the 404 response will be returned
  69. * to the browser.
  70. */
  71. list($method, $uri) = array(Request::method(), URI::get());
  72. $route = $container->core('routing.router')->route($method, $uri);
  73. if ( ! is_null($route))
  74. {
  75. $response = $container->core('routing.caller')->call($route);
  76. }
  77. else
  78. {
  79. $response = Response::error('404');
  80. }
  81. /**
  82. * Stringify the response. We need to force the response to be
  83. * stringed before closing the session, since the developer may
  84. * be using the session within their views, so we cannot age
  85. * the session data until the view is rendered.
  86. */
  87. $response->content = $response->render();
  88. /**
  89. * Close the session and write the active payload to persistent
  90. * storage. The input for the current request is also flashed
  91. * to the session so it will be available for the next request
  92. * via the Input::old method.
  93. */
  94. if (isset($session))
  95. {
  96. $flash = array(Input::old_input => Input::get());
  97. $session->close($container->core('session'), Config::get('session'), $flash);
  98. }
  99. /**
  100. * Finally, we can send the response to the browser.
  101. */
  102. $response->send();