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