laravel.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php namespace Laravel;
  2. // --------------------------------------------------------------
  3. // Bootstrap the core framework components.
  4. // --------------------------------------------------------------
  5. require 'bootstrap.php';
  6. // --------------------------------------------------------------
  7. // Set the error reporting and display levels.
  8. // --------------------------------------------------------------
  9. error_reporting(-1);
  10. ini_set('display_errors', 'Off');
  11. // --------------------------------------------------------------
  12. // Register the error / exception handlers.
  13. // --------------------------------------------------------------
  14. set_exception_handler(function($e) use ($application)
  15. {
  16. call_user_func($application->config->get('error.handler'), $e);
  17. });
  18. set_error_handler(function($number, $error, $file, $line) use ($application)
  19. {
  20. $exception = new \ErrorException($error, $number, 0, $file, $line);
  21. call_user_func($application->config->get('error.handler'), $exception);
  22. });
  23. register_shutdown_function(function() use ($application)
  24. {
  25. if ( ! is_null($error = error_get_last()))
  26. {
  27. $exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
  28. call_user_func($application->config->get('error.handler'), $exception);
  29. }
  30. });
  31. // --------------------------------------------------------------
  32. // Set the default timezone.
  33. // --------------------------------------------------------------
  34. date_default_timezone_set($application->config->get('application.timezone'));
  35. // --------------------------------------------------------------
  36. // Initialize the request instance for the request.
  37. // --------------------------------------------------------------
  38. $application->request = new Request($_SERVER, $application->config->get('application.url'));
  39. $application->container->instance('laravel.request', $application->request);
  40. // --------------------------------------------------------------
  41. // Load the session and session manager.
  42. // --------------------------------------------------------------
  43. if ($application->config->get('session.driver') !== '')
  44. {
  45. $application->session = Session\Manager::driver($application->container, $application->config->get('session.driver'));
  46. $application->container->instance('laravel.session.driver', $application->session);
  47. $application->session->start($application->input->cookies->get('laravel_session'), $application->config->get('session.lifetime'));
  48. }
  49. // --------------------------------------------------------------
  50. // Load the packages that are in the auto-loaded packages array.
  51. // --------------------------------------------------------------
  52. $packages = $application->config->get('application.packages');
  53. if (count($packages) > 0)
  54. {
  55. $application->package->load($packages);
  56. }
  57. unset($packages);
  58. // --------------------------------------------------------------
  59. // Route the request and get the response from the route.
  60. // --------------------------------------------------------------
  61. $route = $application->container->resolve('laravel.router')->route();
  62. if ( ! is_null($route))
  63. {
  64. $route->filters = require APP_PATH.'filters'.EXT;
  65. $response = $route->call($application);
  66. }
  67. else
  68. {
  69. $response = new Error('404');
  70. }
  71. // --------------------------------------------------------------
  72. // Stringify the response.
  73. // --------------------------------------------------------------
  74. $response->content = $response->render();
  75. // --------------------------------------------------------------
  76. // Close the session.
  77. // --------------------------------------------------------------
  78. if ( ! is_null($application->session))
  79. {
  80. $application->session->close($application->input, $application->config->get('session'));
  81. }
  82. // --------------------------------------------------------------
  83. // Send the response to the browser.
  84. // --------------------------------------------------------------
  85. $response->send();