/application/bootstrap.php

https://github.com/paulcinelli/kohanajobs · PHP · 149 lines · 67 code · 17 blank · 65 comment · 2 complexity · 3a5edc8e74cfda5fa50f34850f821ca0 MD5 · raw file

  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. //-- Environment setup --------------------------------------------------------
  3. /**
  4. * Set the production status by the domain.
  5. * Note: the default value for Kohana::$environment is Kohana::DEVELOPMENT.
  6. */
  7. if ($_SERVER['HTTP_HOST'] !== 'localhost')
  8. {
  9. Kohana::$environment = Kohana::PRODUCTION;
  10. }
  11. /**
  12. * Set the default time zone.
  13. *
  14. * @see http://docs.kohanaphp.com/about.configuration
  15. * @see http://php.net/timezones
  16. */
  17. date_default_timezone_set('Europe/Brussels');
  18. /**
  19. * Set the default locale.
  20. *
  21. * @see http://docs.kohanaphp.com/about.configuration
  22. * @see http://php.net/setlocale
  23. */
  24. setlocale(LC_ALL, 'en_US.utf-8');
  25. /**
  26. * Enable the Kohana auto-loader.
  27. *
  28. * @see http://docs.kohanaphp.com/about.autoloading
  29. * @see http://php.net/spl_autoload_register
  30. */
  31. spl_autoload_register(array('Kohana', 'auto_load'));
  32. /**
  33. * Enable the Kohana auto-loader for unserialization.
  34. *
  35. * @see http://php.net/spl_autoload_call
  36. * @see http://php.net/manual/var.configuration.php#unserialize-callback-func
  37. */
  38. ini_set('unserialize_callback_func', 'spl_autoload_call');
  39. //-- Configuration and initialization -----------------------------------------
  40. /**
  41. * Initialize Kohana, setting the default options.
  42. *
  43. * The following options are available:
  44. *
  45. * - string base_url path, and optionally domain, of your application NULL
  46. * - string index_file name of your index file, usually "index.php" index.php
  47. * - string charset internal character set used for input and output utf-8
  48. * - string cache_dir set the internal cache directory APPPATH/cache
  49. * - boolean errors enable or disable error handling TRUE
  50. * - boolean profile enable or disable internal profiling TRUE
  51. * - boolean caching enable or disable internal caching FALSE
  52. */
  53. Kohana::init(array(
  54. 'base_url' => Kohana::$environment === Kohana::PRODUCTION ? '/' : '/github/kohanajobs/',
  55. 'index_file' => FALSE,
  56. 'profile' => Kohana::$environment !== Kohana::PRODUCTION,
  57. 'caching' => Kohana::$environment === Kohana::PRODUCTION,
  58. ));
  59. /**
  60. * Attach the file write to logging. Multiple writers are supported.
  61. */
  62. Kohana::$log->attach(new Kohana_Log_File(APPPATH.'logs'));
  63. /**
  64. * Attach a file reader to config. Multiple readers are supported.
  65. */
  66. Kohana::$config->attach(new Kohana_Config_File);
  67. /**
  68. * Enable modules. Modules are referenced by a relative or absolute path.
  69. */
  70. Kohana::modules(array(
  71. 'auth' => MODPATH.'auth',
  72. 'oauth' => MODPATH.'oauth',
  73. 'database' => MODPATH.'database',
  74. 'orm' => MODPATH.'orm',
  75. 'pagination' => MODPATH.'pagination',
  76. ));
  77. /**
  78. * Set the routes. Each route must have a minimum of a name, a URI and a set of
  79. * defaults for the URI.
  80. */
  81. if ( ! Route::cache())
  82. {
  83. // List of all jobs
  84. Route::set('jobs', '')
  85. ->defaults(array(
  86. 'controller' => 'jobs',
  87. 'action' => 'index',
  88. ));
  89. // A single job
  90. Route::set('job', 'jobs/<id>', array('id' => '\d++'))
  91. ->defaults(array(
  92. 'controller' => 'job',
  93. 'action' => 'index',
  94. ));
  95. // Post a new job
  96. Route::set('post', 'post')
  97. ->defaults(array(
  98. 'controller' => 'post',
  99. 'action' => 'index',
  100. ));
  101. // User system related
  102. Route::set('user', 'user/<action>')
  103. ->defaults(array(
  104. 'controller' => 'user',
  105. 'action' => 'index',
  106. ));
  107. Route::set('user/confirm_signup', 'user/confirm_signup/<id>/<code>', array('id' => '\d++'))
  108. ->defaults(array(
  109. 'controller' => 'user',
  110. 'action' => 'confirm_signup',
  111. ));
  112. Route::set('user/confirm_email', 'user/confirm_email/<id>/<code>/<new_email>', array('id' => '\d++'))
  113. ->defaults(array(
  114. 'controller' => 'user',
  115. 'action' => 'confirm_email',
  116. ));
  117. Route::set('user/confirm_reset_password', 'user/confirm_reset_password/<id>/<code>/<time>', array('id' => '\d++', 'time' => '\d++'))
  118. ->defaults(array(
  119. 'controller' => 'user',
  120. 'action' => 'confirm_reset_password',
  121. ));
  122. // Cache the routes in production
  123. Route::cache(Kohana::$environment === Kohana::PRODUCTION);
  124. }
  125. /**
  126. * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
  127. * If no source is specified, the URI will be automatically detected.
  128. */
  129. echo Request::instance()
  130. ->execute()
  131. ->send_headers()
  132. ->response;