index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Laravel - A clean and classy framework for PHP web development.
  4. *
  5. * @package Laravel
  6. * @version 1.0.0 Beta 2
  7. * @author Taylor Otwell
  8. * @license MIT License
  9. * @link http://laravel.com
  10. */
  11. // --------------------------------------------------------------
  12. // Set the framework starting time.
  13. // --------------------------------------------------------------
  14. define('LARAVEL_START', microtime(true));
  15. // --------------------------------------------------------------
  16. // Define the framework paths.
  17. // --------------------------------------------------------------
  18. define('APP_PATH', realpath('../application').'/');
  19. define('SYS_PATH', realpath('../system').'/');
  20. define('BASE_PATH', realpath('../').'/');
  21. define('PUBLIC_PATH', realpath(__DIR__.'/'));
  22. // --------------------------------------------------------------
  23. // Define the PHP file extension.
  24. // --------------------------------------------------------------
  25. define('EXT', '.php');
  26. // --------------------------------------------------------------
  27. // Load the configuration, error, and string classes.
  28. // --------------------------------------------------------------
  29. require SYS_PATH.'config'.EXT;
  30. require SYS_PATH.'error'.EXT;
  31. require SYS_PATH.'str'.EXT;
  32. // --------------------------------------------------------------
  33. // Register the auto-loader.
  34. // --------------------------------------------------------------
  35. spl_autoload_register(require SYS_PATH.'loader'.EXT);
  36. // --------------------------------------------------------------
  37. // Set the Laravel starting time in the Benchmark class.
  38. // --------------------------------------------------------------
  39. System\Benchmark::$marks['laravel'] = LARAVEL_START;
  40. // --------------------------------------------------------------
  41. // Set the error reporting level.
  42. // --------------------------------------------------------------
  43. error_reporting((System\Config::get('error.detail')) ? E_ALL | E_STRICT : 0);
  44. // --------------------------------------------------------------
  45. // Register the error handlers.
  46. // --------------------------------------------------------------
  47. set_exception_handler(function($e)
  48. {
  49. System\Error::handle($e);
  50. });
  51. set_error_handler(function($number, $error, $file, $line)
  52. {
  53. System\Error::handle(new ErrorException($error, 0, $number, $file, $line));
  54. });
  55. register_shutdown_function(function()
  56. {
  57. if ( ! is_null($error = error_get_last()))
  58. {
  59. System\Error::handle(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
  60. }
  61. });
  62. // --------------------------------------------------------------
  63. // Set the default timezone.
  64. // --------------------------------------------------------------
  65. date_default_timezone_set(System\Config::get('application.timezone'));
  66. // --------------------------------------------------------------
  67. // Load the session.
  68. // --------------------------------------------------------------
  69. if (System\Config::get('session.driver') != '')
  70. {
  71. System\Session::load();
  72. }
  73. // --------------------------------------------------------------
  74. // Execute the global "before" filter.
  75. // --------------------------------------------------------------
  76. $response = System\Filter::call('before', array(), true);
  77. // --------------------------------------------------------------
  78. // Only execute the route function if the "before" filter did
  79. // not override by sending a response.
  80. // --------------------------------------------------------------
  81. if (is_null($response))
  82. {
  83. // ----------------------------------------------------------
  84. // Route the request to the proper route.
  85. // ----------------------------------------------------------
  86. $route = System\Router::route(Request::method(), Request::uri());
  87. // ----------------------------------------------------------
  88. // Execute the route function.
  89. // ----------------------------------------------------------
  90. if ( ! is_null($route))
  91. {
  92. $response = $route->call();
  93. }
  94. else
  95. {
  96. $response = System\Response::make(View::make('error/404'), 404);
  97. }
  98. }
  99. else
  100. {
  101. $response = System\Response::prepare($response);
  102. }
  103. // ----------------------------------------------------------
  104. // Execute the global "after" filter.
  105. // ----------------------------------------------------------
  106. System\Filter::call('after', array($response));
  107. // ----------------------------------------------------------
  108. // Stringify the response.
  109. // ----------------------------------------------------------
  110. $response->content = (string) $response->content;
  111. // --------------------------------------------------------------
  112. // Close the session.
  113. // --------------------------------------------------------------
  114. if (System\Config::get('session.driver') != '')
  115. {
  116. System\Session::close();
  117. }
  118. // --------------------------------------------------------------
  119. // Send the response to the browser.
  120. // --------------------------------------------------------------
  121. $response->send();