index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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('BASE_PATH', realpath('../').'/');
  19. define('APP_PATH', realpath('../application').'/');
  20. define('SYS_PATH', realpath('../system').'/');
  21. define('PUBLIC_PATH', realpath(__DIR__.'/'));
  22. define('PACKAGE_PATH', APP_PATH.'packages/');
  23. // --------------------------------------------------------------
  24. // Define the PHP file extension.
  25. // --------------------------------------------------------------
  26. define('EXT', '.php');
  27. // --------------------------------------------------------------
  28. // Load the configuration, error, and string classes.
  29. // --------------------------------------------------------------
  30. require SYS_PATH.'config'.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. require_once SYS_PATH.'error'.EXT;
  50. System\Error::handle($e);
  51. });
  52. set_error_handler(function($number, $error, $file, $line)
  53. {
  54. require_once SYS_PATH.'error'.EXT;
  55. System\Error::handle(new ErrorException($error, 0, $number, $file, $line));
  56. });
  57. register_shutdown_function(function()
  58. {
  59. if ( ! is_null($error = error_get_last()))
  60. {
  61. require_once SYS_PATH.'error'.EXT;
  62. System\Error::handle(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
  63. }
  64. });
  65. // --------------------------------------------------------------
  66. // Set the default timezone.
  67. // --------------------------------------------------------------
  68. date_default_timezone_set(System\Config::get('application.timezone'));
  69. // --------------------------------------------------------------
  70. // Load the session.
  71. // --------------------------------------------------------------
  72. if (System\Config::get('session.driver') != '')
  73. {
  74. System\Session::load();
  75. }
  76. // --------------------------------------------------------------
  77. // Execute the global "before" filter.
  78. // --------------------------------------------------------------
  79. $response = System\Filter::call('before', array(), true);
  80. // --------------------------------------------------------------
  81. // Only execute the route function if the "before" filter did
  82. // not override by sending a response.
  83. // --------------------------------------------------------------
  84. if (is_null($response))
  85. {
  86. // ----------------------------------------------------------
  87. // Route the request to the proper route.
  88. // ----------------------------------------------------------
  89. $route = System\Router::route(Request::method(), Request::uri());
  90. // ----------------------------------------------------------
  91. // Execute the route function.
  92. // ----------------------------------------------------------
  93. if ( ! is_null($route))
  94. {
  95. $response = $route->call();
  96. }
  97. else
  98. {
  99. $response = System\Response::make(View::make('error/404'), 404);
  100. }
  101. }
  102. else
  103. {
  104. $response = System\Response::prepare($response);
  105. }
  106. // ----------------------------------------------------------
  107. // Execute the global "after" filter.
  108. // ----------------------------------------------------------
  109. System\Filter::call('after', array($response));
  110. // ----------------------------------------------------------
  111. // Stringify the response.
  112. // ----------------------------------------------------------
  113. $response->content = (string) $response->content;
  114. // --------------------------------------------------------------
  115. // Close the session.
  116. // --------------------------------------------------------------
  117. if (System\Config::get('session.driver') != '')
  118. {
  119. System\Session::close();
  120. }
  121. // --------------------------------------------------------------
  122. // Send the response to the browser.
  123. // --------------------------------------------------------------
  124. $response->send();