laravel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. $cookie = $container->resolve('laravel.input')->cookies->get('laravel_session');
  42. $container->resolve('laravel.session')->start($cookie, $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.
  62. // --------------------------------------------------------------
  63. if ($config->get('session.driver') !== '')
  64. {
  65. $container->resolve('laravel.session')->close($container->resolve('laravel.input'));
  66. }
  67. // --------------------------------------------------------------
  68. // Send the response to the browser.
  69. // --------------------------------------------------------------
  70. $response->send();