index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.'str'.EXT;
  31. // --------------------------------------------------------------
  32. // Register the auto-loader.
  33. // --------------------------------------------------------------
  34. spl_autoload_register(require SYS_PATH.'loader'.EXT);
  35. // --------------------------------------------------------------
  36. // Set the Laravel starting time in the Benchmark class.
  37. // --------------------------------------------------------------
  38. System\Benchmark::$marks['laravel'] = LARAVEL_START;
  39. // --------------------------------------------------------------
  40. // Set the error reporting level.
  41. // --------------------------------------------------------------
  42. error_reporting((System\Config::get('error.detail')) ? E_ALL | E_STRICT : 0);
  43. // --------------------------------------------------------------
  44. // Register the error handlers.
  45. // --------------------------------------------------------------
  46. set_exception_handler(function($e)
  47. {
  48. require_once SYS_PATH.'error'.EXT;
  49. System\Error::handle($e);
  50. });
  51. set_error_handler(function($number, $error, $file, $line)
  52. {
  53. require_once SYS_PATH.'error'.EXT;
  54. System\Error::handle(new ErrorException($error, 0, $number, $file, $line));
  55. });
  56. register_shutdown_function(function()
  57. {
  58. if ( ! is_null($error = error_get_last()))
  59. {
  60. require_once SYS_PATH.'error'.EXT;
  61. System\Error::handle(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
  62. }
  63. });
  64. // --------------------------------------------------------------
  65. // Set the default timezone.
  66. // --------------------------------------------------------------
  67. date_default_timezone_set(System\Config::get('application.timezone'));
  68. // --------------------------------------------------------------
  69. // Load the session.
  70. // --------------------------------------------------------------
  71. if (System\Config::get('session.driver') != '')
  72. {
  73. System\Session::load();
  74. }
  75. // --------------------------------------------------------------
  76. // Execute the global "before" filter.
  77. // --------------------------------------------------------------
  78. $response = System\Filter::call('before', array(), true);
  79. // --------------------------------------------------------------
  80. // Only execute the route function if the "before" filter did
  81. // not override by sending a response.
  82. // --------------------------------------------------------------
  83. if (is_null($response))
  84. {
  85. // ----------------------------------------------------------
  86. // Route the request to the proper route.
  87. // ----------------------------------------------------------
  88. $route = System\Router::route(Request::method(), Request::uri());
  89. // ----------------------------------------------------------
  90. // Execute the route function.
  91. // ----------------------------------------------------------
  92. if ( ! is_null($route))
  93. {
  94. $response = $route->call();
  95. }
  96. else
  97. {
  98. $response = System\Response::make(View::make('error/404'), 404);
  99. }
  100. }
  101. else
  102. {
  103. $response = System\Response::prepare($response);
  104. }
  105. // ----------------------------------------------------------
  106. // Execute the global "after" filter.
  107. // ----------------------------------------------------------
  108. System\Filter::call('after', array($response));
  109. // ----------------------------------------------------------
  110. // Stringify the response.
  111. // ----------------------------------------------------------
  112. $response->content = (string) $response->content;
  113. // --------------------------------------------------------------
  114. // Close the session.
  115. // --------------------------------------------------------------
  116. if (System\Config::get('session.driver') != '')
  117. {
  118. System\Session::close();
  119. }
  120. // --------------------------------------------------------------
  121. // Send the response to the browser.
  122. // --------------------------------------------------------------
  123. $response->send();