index.php 5.3 KB

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