index.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Fuel is a fast, lightweight, community driven PHP5 framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. /**
  13. * Set error reporting and display errors settings. You will want to change these when in production.
  14. */
  15. error_reporting(-1);
  16. ini_set('display_errors', 1);
  17. /**
  18. * Website document root
  19. */
  20. define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR);
  21. /**
  22. * Path to the application directory.
  23. */
  24. define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR);
  25. /**
  26. * Path to the default packages directory.
  27. */
  28. define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR);
  29. /**
  30. * The path to the framework core.
  31. */
  32. define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);
  33. // Get the start time and memory for use later
  34. defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
  35. defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage());
  36. // Boot the app
  37. require APPPATH.'bootstrap.php';
  38. // Generate the request, execute it and send the output.
  39. try
  40. {
  41. $response = Request::forge()->execute()->response();
  42. }
  43. catch (HttpNotFoundException $e)
  44. {
  45. $route = array_key_exists('_404_', Router::$routes) ? Router::$routes['_404_']->translation : Config::get('routes._404_');
  46. if($route instanceof Closure)
  47. {
  48. $response = $route();
  49. if( ! $response instanceof Response)
  50. {
  51. $response = Response::forge($response);
  52. }
  53. }
  54. elseif ($route)
  55. {
  56. $response = Request::forge($route, false)->execute()->response();
  57. }
  58. else
  59. {
  60. throw $e;
  61. }
  62. }
  63. // This will add the execution time and memory usage to the output.
  64. // Comment this out if you don't use it.
  65. $bm = Profiler::app_total();
  66. $response->body(
  67. str_replace(
  68. array('{exec_time}', '{mem_usage}'),
  69. array(round($bm[0], 4), round($bm[1] / pow(1024, 2), 3)),
  70. $response->body()
  71. )
  72. );
  73. $response->send(true);