index.php 5.0 KB

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