laravel.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php namespace Laravel;
  2. // --------------------------------------------------------------
  3. // Bootstrap the core framework components.
  4. // --------------------------------------------------------------
  5. require 'bootstrap.php';
  6. // --------------------------------------------------------------
  7. // Get an instance of the configuration manager.
  8. // --------------------------------------------------------------
  9. $config = $container->resolve('laravel.config');
  10. set_exception_handler(function($e) use ($config)
  11. {
  12. call_user_func($config->get('error.handler'), $e);
  13. });
  14. set_error_handler(function($number, $error, $file, $line) use ($config)
  15. {
  16. $exception = new \ErrorException($error, $number, 0, $file, $line);
  17. call_user_func($config->get('error.handler'), $exception);
  18. });
  19. register_shutdown_function(function() use ($config)
  20. {
  21. if ( ! is_null($error = error_get_last()))
  22. {
  23. $exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
  24. call_user_func($config->get('error.handler'), $exception);
  25. }
  26. });
  27. // --------------------------------------------------------------
  28. // Set the error reporting and display levels.
  29. // --------------------------------------------------------------
  30. error_reporting(-1);
  31. ini_set('display_errors', 'Off');
  32. // --------------------------------------------------------------
  33. // Set the default timezone.
  34. // --------------------------------------------------------------
  35. date_default_timezone_set($config->get('application.timezone'));
  36. // --------------------------------------------------------------
  37. // Load the session and session manager.
  38. // --------------------------------------------------------------
  39. if ($config->get('session.driver') !== '')
  40. {
  41. $session = $container->resolve('laravel.session.manager');
  42. $container->instance('laravel.session', $session->payload($config->get('session')));
  43. }
  44. // --------------------------------------------------------------
  45. // Route the request and get the response from the route.
  46. // --------------------------------------------------------------
  47. $route = $container->resolve('laravel.routing.router')->route($container->resolve('laravel.request'));
  48. if ( ! is_null($route))
  49. {
  50. $response = $container->resolve('laravel.routing.caller')->call($route);
  51. }
  52. else
  53. {
  54. $response = $container->resolve('laravel.response')->error('404');
  55. }
  56. // --------------------------------------------------------------
  57. // Stringify the response.
  58. // --------------------------------------------------------------
  59. $response->content = $response->render();
  60. // --------------------------------------------------------------
  61. // Close the session and write the session cookie.
  62. // --------------------------------------------------------------
  63. if (isset($session))
  64. {
  65. $session->close($container->resolve('laravel.session'), $config->get('session'));
  66. }
  67. // --------------------------------------------------------------
  68. // Send the queued cookies to the browser.
  69. // --------------------------------------------------------------
  70. $container->resolve('laravel.cookie')->send();
  71. // --------------------------------------------------------------
  72. // Send the response to the browser.
  73. // --------------------------------------------------------------
  74. $response->send();