laravel.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. // Load the session and session manager.
  37. // --------------------------------------------------------------
  38. if ($application->config->get('session.driver') !== '')
  39. {
  40. $cookie = $application->input->cookies->get('laravel_session');
  41. $application->session->start($cookie, $application->config->get('session.lifetime'));
  42. }
  43. // --------------------------------------------------------------
  44. // Load the packages that are in the auto-loaded packages array.
  45. // --------------------------------------------------------------
  46. $packages = $application->config->get('application.packages');
  47. if (count($packages) > 0)
  48. {
  49. $application->package->load($packages);
  50. }
  51. unset($packages);
  52. // --------------------------------------------------------------
  53. // Route the request and get the response from the route.
  54. // --------------------------------------------------------------
  55. $route = $application->router->route();
  56. if ( ! is_null($route))
  57. {
  58. $route->filters = require APP_PATH.'filters'.EXT;
  59. $response = $route->call($application);
  60. }
  61. else
  62. {
  63. $response = $application->response->error('404');
  64. }
  65. // --------------------------------------------------------------
  66. // Stringify the response.
  67. // --------------------------------------------------------------
  68. $response->content = $response->render();
  69. // --------------------------------------------------------------
  70. // Close the session.
  71. // --------------------------------------------------------------
  72. if ($application->config->get('session.driver') !== '')
  73. {
  74. $application->session->close($application->input, $application->config->get('session'));
  75. }
  76. // --------------------------------------------------------------
  77. // Send the response to the browser.
  78. // --------------------------------------------------------------
  79. $response->send();