index.php 4.1 KB

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