You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
8.3KB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 0.10.8
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. /*
  17. * This file is loaded by your src/Application.php bootstrap method.
  18. * Feel free to extend/extract parts of the bootstrap process into your own files
  19. * to suit your needs/preferences.
  20. */
  21. /*
  22. * Configure paths required to find CakePHP + general filepath constants
  23. */
  24. require __DIR__ . DIRECTORY_SEPARATOR . 'paths.php';
  25. /*
  26. * Bootstrap CakePHP
  27. * Currently all this does is initialize the router (without loading your routes)
  28. */
  29. require CORE_PATH . 'config' . DS . 'bootstrap.php';
  30. use Cake\Cache\Cache;
  31. use Cake\Core\Configure;
  32. use Cake\Core\Configure\Engine\PhpConfig;
  33. use Cake\Datasource\ConnectionManager;
  34. use Cake\Error\ErrorTrap;
  35. use Cake\Error\ExceptionTrap;
  36. use Cake\Http\ServerRequest;
  37. use Cake\Log\Log;
  38. use Cake\Mailer\Mailer;
  39. use Cake\Mailer\TransportFactory;
  40. use Cake\Routing\Router;
  41. use Cake\Utility\Security;
  42. use Detection\MobileDetect;
  43. use function Cake\Core\env;
  44. /*
  45. * Load global functions for collections, translations, debugging etc.
  46. */
  47. require CAKE . 'functions.php';
  48. /*
  49. * See https://github.com/josegonzalez/php-dotenv for API details.
  50. *
  51. * Uncomment block of code below if you want to use `.env` file during development.
  52. * You should copy `config/.env.example` to `config/.env` and set/modify the
  53. * variables as required.
  54. *
  55. * The purpose of the .env file is to emulate the presence of the environment
  56. * variables like they would be present in production.
  57. *
  58. * If you use .env files, be careful to not commit them to source control to avoid
  59. * security risks. See https://github.com/josegonzalez/php-dotenv#general-security-information
  60. * for more information for recommended practices.
  61. */
  62. // if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
  63. // $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
  64. // $dotenv->parse()
  65. // ->putenv()
  66. // ->toEnv()
  67. // ->toServer();
  68. // }
  69. /*
  70. * Initializes default Config store and loads the main configuration file (app.php)
  71. *
  72. * CakePHP contains 2 configuration files after project creation:
  73. * - `config/app.php` for the default application configuration.
  74. * - `config/app_local.php` for environment specific configuration.
  75. */
  76. try {
  77. Configure::config('default', new PhpConfig());
  78. Configure::load('app', 'default', false);
  79. } catch (Exception $e) {
  80. exit($e->getMessage() . "\n");
  81. }
  82. /*
  83. * Load an environment local configuration file to provide overrides to your configuration.
  84. * Notice: For security reasons app_local.php **should not** be included in your git repo.
  85. */
  86. if (file_exists(CONFIG . 'app_local.php')) {
  87. Configure::load('app_local', 'default');
  88. }
  89. /*
  90. * When debug = true the metadata cache should only last for a short time.
  91. */
  92. if (Configure::read('debug')) {
  93. Configure::write('Cache._cake_model_.duration', '+1 minute');
  94. Configure::write('Cache._cake_translations_.duration', '+1 minute');
  95. }
  96. /*
  97. * Set the default server timezone. Using UTC makes time calculations / conversions easier.
  98. * Check https://php.net/manual/en/timezones.php for list of valid timezone strings.
  99. */
  100. date_default_timezone_set(Configure::read('App.defaultTimezone'));
  101. /*
  102. * Configure the mbstring extension to use the correct encoding.
  103. */
  104. mb_internal_encoding(Configure::read('App.encoding'));
  105. /*
  106. * Set the default locale. This controls how dates, number and currency is
  107. * formatted and sets the default language to use for translations.
  108. */
  109. ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
  110. /*
  111. * Register application error and exception handlers.
  112. */
  113. (new ErrorTrap(Configure::read('Error')))->register();
  114. (new ExceptionTrap(Configure::read('Error')))->register();
  115. /*
  116. * CLI/Command specific configuration.
  117. */
  118. if (PHP_SAPI === 'cli') {
  119. // Set the fullBaseUrl to allow URLs to be generated in commands.
  120. // This is useful when sending email from commands.
  121. // Configure::write('App.fullBaseUrl', php_uname('n'));
  122. // Set logs to different files so they don't have permission conflicts.
  123. if (Configure::check('Log.debug')) {
  124. Configure::write('Log.debug.file', 'cli-debug');
  125. }
  126. if (Configure::check('Log.error')) {
  127. Configure::write('Log.error.file', 'cli-error');
  128. }
  129. }
  130. /*
  131. * Set the full base URL for the application.
  132. *
  133. * SECURITY: In production, App.fullBaseUrl MUST be explicitly configured to prevent
  134. * Host Header Injection attacks. The HostHeaderMiddleware enforces this requirement
  135. * and validates incoming Host headers against the configured value.
  136. *
  137. * Set APP_FULL_BASE_URL in your environment variables or configure App.fullBaseUrl
  138. * in config/app.php or config/app_local.php
  139. *
  140. * Example: APP_FULL_BASE_URL=https://example.com
  141. */
  142. $fullBaseUrl = Configure::read('App.fullBaseUrl');
  143. if (!$fullBaseUrl) {
  144. $httpHost = env('HTTP_HOST');
  145. /*
  146. * Development mode fallback: Use HTTP_HOST for convenience.
  147. * WARNING: This is ONLY safe in development. In production, the
  148. * HostHeaderMiddleware will reject requests when fullBaseUrl is not configured.
  149. */
  150. if ($httpHost) {
  151. $s = null;
  152. if (env('HTTPS') || env('HTTP_X_FORWARDED_PROTO') === 'https') {
  153. $s = 's';
  154. }
  155. $fullBaseUrl = 'http' . $s . '://' . $httpHost;
  156. }
  157. unset($httpHost, $s);
  158. }
  159. if ($fullBaseUrl) {
  160. Router::fullBaseUrl($fullBaseUrl);
  161. }
  162. unset($fullBaseUrl);
  163. /*
  164. * Apply the loaded configuration settings to their respective systems.
  165. * This will also remove the loaded config data from memory.
  166. */
  167. Cache::setConfig(Configure::consume('Cache'));
  168. ConnectionManager::setConfig(Configure::consume('Datasources'));
  169. TransportFactory::setConfig(Configure::consume('EmailTransport'));
  170. Mailer::setConfig(Configure::consume('Email'));
  171. Log::setConfig(Configure::consume('Log'));
  172. Security::setSalt(Configure::consume('Security.salt'));
  173. /*
  174. * Setup detectors for mobile and tablet.
  175. * If you don't use these checks you can safely remove this code
  176. * and the mobiledetect package from composer.json.
  177. */
  178. ServerRequest::addDetector('mobile', function ($request) {
  179. $detector = new MobileDetect();
  180. return $detector->isMobile();
  181. });
  182. ServerRequest::addDetector('tablet', function ($request) {
  183. $detector = new MobileDetect();
  184. return $detector->isTablet();
  185. });
  186. /*
  187. * You can enable default locale format parsing by adding calls
  188. * to `useLocaleParser()`. This enables the automatic conversion of
  189. * locale specific date formats when processing request data. For details see
  190. * @link https://book.cakephp.org/5/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
  191. */
  192. // \Cake\Database\TypeFactory::build('time')->useLocaleParser();
  193. // \Cake\Database\TypeFactory::build('date')->useLocaleParser();
  194. // \Cake\Database\TypeFactory::build('datetime')->useLocaleParser();
  195. // \Cake\Database\TypeFactory::build('timestamp')->useLocaleParser();
  196. // \Cake\Database\TypeFactory::build('datetimefractional')->useLocaleParser();
  197. // \Cake\Database\TypeFactory::build('timestampfractional')->useLocaleParser();
  198. // \Cake\Database\TypeFactory::build('datetimetimezone')->useLocaleParser();
  199. // \Cake\Database\TypeFactory::build('timestamptimezone')->useLocaleParser();
  200. /*
  201. * Custom Inflector rules, can be set to correctly pluralize or singularize
  202. * table, model, controller names or whatever other string is passed to the
  203. * inflection functions.
  204. */
  205. // \Cake\Utility\Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
  206. // \Cake\Utility\Inflector::rules('irregular', ['red' => 'redlings']);
  207. // \Cake\Utility\Inflector::rules('uninflected', ['dontinflectme']);
  208. // set a custom date and time format
  209. // see https://book.cakephp.org/5/en/core-libraries/time.html#setting-the-default-locale-and-format-string
  210. // and https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
  211. // \Cake\I18n\Date::setToStringFormat('dd.MM.yyyy');
  212. // \Cake\I18n\Time::setToStringFormat('dd.MM.yyyy HH:mm');

Powered by TurnKey Linux.