Bootstrap.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Bootstrap
  4. *
  5. * This file contains initialization code run immediately after system startup.
  6. * Setup i18n and l10n handling, configure system, prepare event hooks.
  7. *
  8. * @package MicroMVC
  9. * @author David Pennington
  10. * @copyright (c) 2010 MicroMVC Framework
  11. * @license http://micromvc.com/license
  12. ********************************** 80 Columns *********************************
  13. */
  14. // System Start Time
  15. define('START_TIME', microtime(true));
  16. // System Start Memory
  17. define('START_MEMORY_USAGE', memory_get_usage());
  18. // Extension of all PHP files
  19. define('EXT', '.php');
  20. // Directory separator (Unix-Style works on all OS)
  21. define('DS', '/');
  22. // Absolute path to the system folder
  23. define('SP', realpath(__DIR__). DS);
  24. // Is this an AJAX request?
  25. define('AJAX_REQUEST', strtolower(getenv('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest');
  26. // The current TLD address, scheme, and port
  27. define('DOMAIN', (strtolower(getenv('HTTPS')) == 'on' ? 'https' : 'http') . '://'
  28. . getenv('HTTP_HOST') . (($p = getenv('SERVER_PORT')) != 80 AND $p != 443 ? ":$p" : ''));
  29. // The current site path
  30. define('PATH', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));
  31. require(SP . 'vendor/autoload' . EXT);
  32. // Include common system functions
  33. require(SP . 'Common' . EXT);
  34. \Micro\View::$directory = SP . 'View/';
  35. \Micro\Cookie::$settings = config()->cookie;
  36. // Register events
  37. foreach(config()->events as $event => $class)
  38. {
  39. event($event, NULL, $class);
  40. }
  41. /*
  42. if(preg_match_all('/[\-a-z]{2,}/i', getenv('HTTP_ACCEPT_LANGUAGE'), $locales))
  43. {
  44. $locales = $locales[0];
  45. }
  46. */
  47. // Get locale from user agent
  48. if(isset($_COOKIE['lang']))
  49. {
  50. $preference = $_COOKIE['lang'];
  51. }
  52. else
  53. {
  54. $preference = Locale::acceptFromHttp(getenv('HTTP_ACCEPT_LANGUAGE'));
  55. }
  56. // Match preferred language to those available, defaulting to generic English
  57. $locale = Locale::lookup(config()->languages, $preference, false, 'en');
  58. // Default Locale
  59. Locale::setDefault($locale);
  60. setlocale(LC_ALL, $locale . '.utf-8');
  61. //putenv("LC_ALL", $locale);
  62. // Default timezone of server
  63. date_default_timezone_set('UTC');
  64. // iconv encoding
  65. iconv_set_encoding("internal_encoding", "UTF-8");
  66. // multibyte encoding
  67. mb_internal_encoding('UTF-8');
  68. // Enable global error handling
  69. set_error_handler(array('\Micro\Error', 'handler'));
  70. register_shutdown_function(array('\Micro\Error', 'fatal'));