index.php 4.8 KB

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