laravel.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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::$items['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::$items['session']['driver'] !== '')
  24. {
  25. require SYS_PATH.'cookie'.EXT;
  26. require SYS_PATH.'session/payload'.EXT;
  27. $driver = IoC::container()->core('session.'.Config::$items['session']['driver']);
  28. if ( ! is_null($id = Cookie::get(Session\Payload::cookie)))
  29. {
  30. $payload = new Session\Payload($driver->load($id));
  31. }
  32. else
  33. {
  34. $payload = new Session\Payload;
  35. }
  36. IoC::container()->instance('laravel.session', $payload);
  37. }
  38. /**
  39. * Manually load some core classes that are used on every request
  40. * This allows to avoid using the loader for these classes.
  41. */
  42. require SYS_PATH.'input'.EXT;
  43. require SYS_PATH.'request'.EXT;
  44. require SYS_PATH.'response'.EXT;
  45. require SYS_PATH.'routing/route'.EXT;
  46. require SYS_PATH.'routing/router'.EXT;
  47. require SYS_PATH.'routing/loader'.EXT;
  48. require SYS_PATH.'routing/filter'.EXT;
  49. /**
  50. * Gather the input to the application for the current request.
  51. * The input will be gathered based on the current request method
  52. * and will be set on the Input manager.
  53. */
  54. $input = array();
  55. switch (Request::method())
  56. {
  57. case 'GET':
  58. $input = $_GET;
  59. break;
  60. case 'POST':
  61. $input = $_POST;
  62. break;
  63. case 'PUT':
  64. case 'DELETE':
  65. if (Request::spoofed())
  66. {
  67. $input = $_POST;
  68. }
  69. else
  70. {
  71. parse_str(file_get_contents('php://input'), $input);
  72. }
  73. }
  74. /**
  75. * The spoofed request method is removed from the input so it is
  76. * not unexpectedly included in Input::all() or Input::get().s
  77. */
  78. unset($input[Request::spoofer]);
  79. Input::$input = $input;
  80. /**
  81. * Route the request to the proper route in the application. If a
  82. * route is found, the route will be called with the current request
  83. * instance. If no route is found, the 404 response will be returned
  84. * to the browser.
  85. */
  86. Routing\Filter::register(require APP_PATH.'filters'.EXT);
  87. list($uri, $method) = array(Request::uri(), Request::method());
  88. Request::$route = IoC::container()->core('routing.router')->route($method, $uri);
  89. if ( ! is_null(Request::$route))
  90. {
  91. $response = Request::$route->call();
  92. }
  93. else
  94. {
  95. $response = Response::error('404');
  96. }
  97. /**
  98. * Stringify the response. We need to force the response to be
  99. * stringed before closing the session, since the developer may
  100. * be using the session within their views, so we cannot age
  101. * the session data until the view is rendered.
  102. */
  103. $response->content = $response->render();
  104. /**
  105. * Close the session and write the active payload to persistent
  106. * storage. The session cookie will also be written and if the
  107. * driver is a sweeper, session garbage collection might be
  108. * performed depending on the "sweepage" probability.
  109. */
  110. if (Config::$items['session']['driver'] !== '')
  111. {
  112. IoC::container()->core('session')->save($driver);
  113. }
  114. /**
  115. * Finally, we can send the response to the browser.
  116. */
  117. $response->send();